"AttributeError: 'list' object has no attribute 'findAll'"



我目前正在用Python编写一个网络抓取脚本,以便能够从固定装置中获取逐场足球解说,并将其输入到excel表中。当我尝试运行它时,我一直得到这个:

Traceback (most recent call last):
File "/Users/noahhollander/Desktop/Web_Scraping/play_by_play.py", line 9, in <module>
tbody = soup('table',{"class":"content"})[0:].findAll('tr')
AttributeError: 'list' object has no attribute 'findAll'
[Finished in 6.207s]

我读到这可能与这个表是文本格式有关,但我在末尾添加了.text,结果仍然相同。

这是迄今为止我的代码的图片。

您可能需要编写这样的内容。

soup.find_all('table',{"class":"content"})
tbody = []
tclass = soup('table', {"class":"content"})[0:]
for temp in tclass:
for t_temp in temp.find_all('tr'):
tbody.append(t_temp)

这是你想要的结果吗?

div = soup.find('div', {"class": "content"})
tbody = div.find('table').findAll('tr')

你会得到你想要的结果

相关内容

最新更新