![[왕초보] 비개발자를 위한, 웹개발 종합반 3주차 숙제](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbJi51s%2FbtrPEoEEeJr%2F1gxo9ukMni3GR61GBwetOK%2Fimg.png)
[왕초보] 비개발자를 위한, 웹개발 종합반 3주차 숙제Coding2022. 10. 27. 12:55
Table of Contents
728x90
반응형
지니뮤직의 1~50위 곡을 스크래핑 해보세요.
지니뮤직 사이트 : https://www.genie.co.kr/chart/top200?ditc=M&rtm=N&ymd=20210701
순위 / 곡 제목 / 가수를 스크래핑 하면 됩니다.
힌트:
0) 출력 할 때는 print(rank, title, artist) 하면 됩니다!
1) 앞에서 두 글자만 끊기! text[0:2] 를 써보세요!
2) 순위와 곡제목이 깔끔하게 나오지 않을 거예요. 옆에 여백이 있다던가, 다른 글씨도 나온다던가.. 파이썬 내장 함수인 strip()을 잘 연구해보세요!
[ 결과물 ]
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:
title = tr.select_one('td.info > a.title.ellipsis').text.strip()
rank = tr.select_one('td.number').text[0:2].strip()
artist = tr.select_one('td.info > a.artist.ellipsis').text
print(rank, title, artist)
728x90
반응형
'Coding' 카테고리의 다른 글
[왕초보] 비개발자를 위한, 웹개발 종합반 4주차 숙제 (0) | 2022.10.28 |
---|---|
[왕초보] 비개발자를 위한, 웹개발 종합반 4주차 (0) | 2022.10.27 |
[왕초보] 비개발자를 위한, 웹개발 종합반 3주차 (0) | 2022.10.25 |
[왕초보] 비개발자를 위한, 웹개발 종합반 2주차 숙제 (0) | 2022.10.24 |
[왕초보] 비개발자를 위한, 웹개발 종합반 2주차 (1) | 2022.10.22 |
@min' :: 개발을 하자
github : https://github.com/dnjfht
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!