爬虫成功但报错
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/107.0.0.0 Safari/537.36"
}
url = '放评论区'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
tr_list = soup.select('.detail-context tr')
print(tr_list)
f = open('./女排名单/2015女排名单.txt', 'w+', encoding='utf-8')
for tr in tr_list:
td_list = tr.select('td')
name = td_list[0].text.strip()
birthtime=td_list[1].text.strip()
height=td_list[2].text.strip()
smash=td_list[4].text.strip()
block=td_list[5].text.strip()
position = td_list[6].text.strip()
province=td_list[-1].text.strip()
代码可以运行并爬取信息,但会报错“IndexError: list index out of range”,不知道怎么处理