• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    미해결

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

20.12.04 13:19 작성 조회수 133

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(',', '')