
3주차 숙제에서 'text[0:2].strip()' 사용했는데. 15위에 '19금' 때문에 칸이 이상하게 나오는데
어떻게 하면 빈칸 없앨 수 있을까요?
12 비와 당신 이무진
13 Alcohol-Free TWICE (트와이스)
14 롤린 (Rollin') 브레이브걸스 (Brave girls)
15 19금
Peaches (Feat. Daniel Caesar & Giveon) Justin Bieber
16 Dun Dun Dance 오마이걸 (OH MY GIRL)
17 Dynamite 방탄소년단
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')
music = soup.select('#body-content > div.newest-list > div > table > tbody > tr')
for m in music:
rank = m.select_one('td.number').text[0:2].strip()
title = m.select_one('td.info > a.title.ellipsis').text.strip()
artist = m.select_one('td.info > a.artist.ellipsis').text
print(rank, title, artist)
