
1) 가져오기 할 때 마지막 tr 뒤에 붙은 :nth-child(1) 는 어떤 의미인가요? 이 부분은 가지고 오지 않았습니다만,,,,
trs = soup.select(
'# body-content > div.newest-list > div > table > tbody > tr:nth-child(1)')
2) 입력 후 저장을 하면 공백이 생기면서 줄 바꿈 ?? 이 자동으로 돼서 오류가 나는 것 같습니다. 왜 그럴까요 ?
trs = soup.select(
'# body-content > div.newest-list > div > table > tbody > tr:nth-child(1)')
이런 형태로 저장이 되어 버립니다.
작성한 코드 및 에러 메세지
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:nth-child(1)')
for tr in trs:
title = tr.select_one('td.info > a.title.ellipsis').text
