BeautifulSoup找不到具有特定类的表

2024-09-29 21:50:16 发布

您现在位置:Python中文网/ 问答频道 /正文

从本质上讲,我试图从下面给定类名的表中提取文本。我已经编写了从每一行提取文本的其余代码,因此在这方面不需要任何帮助。我只是不明白为什么我会收到这个错误:

"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'})

Tags: no代码文本reyouobjecttableattribute

热门问题