• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    미해결

Gmarket 크롤링 실습문제

20.09.23 20:56 작성 조회수 314

0

안녕하세요,
강의를 잘 따라오면서 열심히 공부하고 있는 수강생입니다. 

gmarket 베스트 상품 크롤링 실습을 따라하면서 아래와 같은 오류가 나서 질문드립니다. 

크롤링한 데이터 다시 크롤링하기 강의 中

2020.09.23일 기준 20번째 title,price,provider_info를 불러올 때 None값이 나타납니다. 코드의 오류일까요 g마켓의 html구조의 문제일까요 

답변부탁드립니다.  

답변 1

답변을 작성해보세요.

0

안녕하세요.

공유드린 자료의 코드를 기반으로, 크롤링 예제를 보여드리고 있는데요.

해당 영상에 첨부드린 crawling_crawling.ipynb 코드와 지금 공유해주신 코드와 달라보여요.

첨부해드리고 영상에서 설명드린 코드는 정상적으로 동작해서요. 혹시 제가 착각하는 것이라면, 새로운 질문으로 올려주시면 되겠지만, 카테고리도 달라보이고 (즉, 다른 링크로 크롤링을 하신 듯 하고), css selector 도 강의에서 설명드린 css selector 와 달라보입니다. 확인부탁드려요. 여기까지 들으셨다면, 성공하신 것 같아요. 감사합니다.

import requests

from bs4 import BeautifulSoup

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

    print (title.get_text(), price.get_text(), title['href'])

import requests

from bs4 import BeautifulSoup

import re                          # 2020.07.25 업데이트 (지마켓 일부 상품 태그 변경, 공지사항 참조부탁드림)

link_re = re.compile('^http://')   # 2020.07.25 업데이트 (지마켓 일부 상품 태그 변경, 공지사항 참조부탁드림)

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

    if link_re.match(title['href']):                  # 2020.07.25 업데이트 (지마켓 일부 상품 태그 변경, 공지사항 참조부탁드림)

        res_info = requests.get(title['href'])

        soup_info = BeautifulSoup(res_info.content, 'html.parser')

        provider_info = soup_info.select_one('div.item-topinfo > div.item-topinfo_headline > p > a > strong')

        print (title.get_text(), price.get_text(), title['href'], provider_info.get_text())