【发布时间】:2023-04-09 02:41:01
【问题描述】:
基本上,我正在尝试从表中提取具有下面给定类标题的文本。我已经编写了从每一行中提取文本的其余代码,因此在这方面我不需要任何帮助。我似乎无法弄清楚为什么会收到此错误:
"ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key
AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?
代码是:
from bs4 import BeautifulSoup
import requests
header = {'User-agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5'}
url = requests.get("http://www.jsugamecocksports.com/boxscore.aspx?path=baseball&id=4109", headers = header).text
soup = BeautifulSoup(url, 'html.parser')
region = soup.find_all('div', {'id': 'inning-all'})
table = region.find('table', {'class': 'sidearm-table play-by-play'})
【问题讨论】:
-
这个错误有什么不清楚的地方?
-
我应该能够使用 find() 正确地从“区域”中提取相应的表吗?
-
@RickAhif:这并不是 Python 真正遇到的问题,更多的是因为您使用
find_all搜索了 多个 区域。 -
错误信息再清楚不过了,也没有迹象表明问题出在其他地方,所以我投票决定关闭它。
标签: python beautifulsoup