리나 Dev토리

웹개발 종합반 3주차 과제 본문

스파르타 웹개발(Flask)

웹개발 종합반 3주차 과제

리나lina 2022. 2. 25. 05:35

지니뮤직 사이트에서 순위, 제목, 가수이름 크롤링하기

뷰티풀숩을 처음 써보았다.

import requests
from bs4 import BeautifulSoup

#브라우저에서 call날린것처럼
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get('https://www.genie.co.kr/chart/top200?ditc=M&rtm=N&ymd=20210701',headers=headers)

soup = BeautifulSoup(data.text, 'html.parser')

#body-content > div.newest-list > div > table > tbody > tr:nth-child(1) > td.number
#body-content > div.newest-list > div > table > tbody > tr:nth-child(1) > td.info > a.title.ellipsis
#body-content > div.newest-list > div > table > tbody > tr:nth-child(1) > td.info > a.artist.ellipsis
songs = soup.select('#body-content > div.newest-list > div > table > tbody > tr')

for song in songs:
    -- 이하 생략 --
Comments