
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
3주차 숙제 부분 질문합니다. 숙제 답안 코드와 동일하게 한 것 같은데 터미널 결과에서 오류가 있습니다.
15번 트랙 부분만 깔끔하게 나오지 않습니다. 무슨 문제 인지 모르겠네요. 오타 혹은 잘못된 부분이 있으면 알려주세요.
추가로
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
에서 마지막에 붙는 .text / .text[0:2] 와 .stript() 를 왜 사용하고, 어떠한 경우에 사용하는지 사용법에 대한 보다 자세한 설명을 듣고 싶습니다.
보고 계신 화면 전체를 캡처해 주시면, 튜터님들이 빠르게 상황을 이해할 수 있어요.

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)
------------------------------------------------------------------------------------------------------------------------------------
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 방탄소년단
→ 15번 트랙이 깔끔하지 않습니다.
