인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

hobul님의 프로필 이미지
hobul

작성한 질문수

[리뉴얼] 파이썬입문과 크롤링기초 부트캠프 [파이썬, 웹, 데이터 이해 기본까지] (업데이트)

지마켓 크롤링 마지막 강의 코드 중에서 질문

작성

·

193

0

수업의 마지막에 설명하시고 제공해 주신 코드 아래 중에서 

-------------------------------------------------------

import requests, openpyxl

from bs4 import BeautifulSoup

excel_file = openpyxl.Workbook()

excel_sheet = excel_file.active

excel_sheet.append(['랭킹', '상품명', '판매가격', '상품상세링크', '판매업체'])

excel_sheet.column_dimensions['B'].width = 80

excel_sheet.column_dimensions['C'].width = 20

excel_sheet.column_dimensions['D'].width = 80

excel_sheet.column_dimensions['E'].width = 20

res = requests.get('http://corners.gmarket.co.kr/Bestsellers?viewType=G&groupCode=G06')

soup = BeautifulSoup(res.content, 'html.parser')

bestlists = soup.select('div.best-list')

bestitems = bestlists[1]

products = bestitems.select('ul > li')

for index, product in enumerate(products):

    title = product.select_one('a.itemname')

    price = product.select_one('div.s-price > strong')        <==    여기 코드에서 가격을 추출한 문자열 중에서

                                                                                                          숫자만  추출하고싶은데 어떻게 하는지요?                                                    ....                                                      

--------------------------------------------------------

답변 1

0

price.get_text() 가 69,000원 이라면, 간단히 replace('원', '') 정도만 해도 되지 않을까요?

또는 다음과 같이 해도 될 것 같습니다.

price.get_text().replace('원', '').replace(',', '')

hobul님의 프로필 이미지
hobul

작성한 질문수

질문하기