지니뮤직 순위, 제목, 가수 텍스트 크롤링하기 완료!! ㅎㅎㅎ

import requests
from bs4 import BeautifulSoup
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')
trs = soup.select('#body-content > div.newest-list > div > table > tbody > tr')
for tr in trs:
rank = tr.select_one('td.number').text[0:2].strip()
title = tr.select_one('td.info > a.title.ellipsis').text.strip()
artist = tr.select_one('td.info >a.artist.ellipsis').text
print(rank, title, artist)
'코딩' 카테고리의 다른 글
코딩교육 4주차(화성 땅 공동구매 페이지 제작) (0) | 2022.07.10 |
---|---|
코딩교육 4주차(flask 기초) (0) | 2022.07.10 |
코딩교육 3주차(몽고 DB) (0) | 2022.07.05 |
코딩교육 3주차(파이썬!!!!!) (0) | 2022.07.05 |
+) 그라데이션 넣기! (0) | 2022.06.29 |