我正在尝试通过网上抓取板球比分webiste获得记分卡。 但我收到此属性错误:
跟踪(最近一次通话结束):
**文件“ J:/ Python程序/ Web抓取工具/ ESPN Cric Info.py”,第6行,位于
soup = BeautifulSoup.find(page.content, 'html.parser')
在查找文件“ J:\ Python程序\ Web Scraper \ venv \ lib \ site-packages \ bs4 \ element.py”中,行1282 l = self.find_all(name,attrs,递归,文本,1,**** kwargs **) ** AttributeError:“字节”对象没有属性“ find_all ” ****
我的代码是:
import requests
from bs4 import BeautifulSoup
page = requests.get('https://www.espncricinfo.com/series/19430/scorecard/1187016/india-vs-bangladesh-1st-test-icc-world-test-championship-2019-2021')
soup = BeautifulSoup.find(page.content, 'html.parser')
scorecard = soup.find(id='gp-inning-01')
print(scorecard)
如果您解决了这个问题,那将是一个很大的帮助。
答案 0 :(得分:0)
import requests
from bs4 import BeautifulSoup
page = requests.get('https://www.espncricinfo.com/series/19430/scorecard/1187016/india-vs-bangladesh-1st-test-icc-world-test-championship-2019-2021')
soup = BeautifulSoup(page.content, 'html.parser')
scorecard = soup.find_all('gp-inning-01')
print(scorecard)
尝试一下
答案 1 :(得分:0)
您犯了两个小错误,但是您的代码几乎是正确的:
.find
之后删除BeautifulSoup
,因为此行仅用于创建汤而不搜索任何内容.text
而不是.content
,因为BeautifulSoup使用的是字符串而不是字节。这是最终代码:
import requests
from bs4 import BeautifulSoup
page = requests.get('https://www.espncricinfo.com/series/19430/scorecard/1187016/india-vs-bangladesh-1st-test-icc-world-test-championship-2019-2021')
soup = BeautifulSoup(page.text, 'html.parser')
scorecard = soup.find(id='gp-inning-01')
print(scorecard)