BeautifulSoup를 이용해서 사이트 정보 추출하자.

예제로 naver.com에서 순위를 찾아보자.

 

※ 소스

import requests
from bs4 import BeautifulSoup

r = requests.get(url)
html_code = r.text
soup = BeautifulSoup(html_code, 'html.parser')
for rank, rank_inner in enumerate(soup.findAll('div', {'class': 'rank_scroll'})):
    for rank, span in enumerate(rank_inner.findAll('span', {'class': 'title'})):
        print ("%d위" % (rank+1), span.text)

 

※ 실행

728x90

+ Recent posts