0
votes

I am trying to web scrape cricket score webiste to get a scorecard. But i am getting this attribute error:

Traceback (most recent call last):
**File "J:/Python Programs/Web Scraper/ESPN Cric Info.py", line 6, in

soup = BeautifulSoup.find(page.content, 'html.parser')

File "J:\Python Programs\Web Scraper\venv\lib\site-packages\bs4\element.py", line 1282, in find l = self.find_all(name, attrs, recursive, text, 1, ****kwargs**) ** AttributeError: 'bytes' object has no attribute 'find_all'****

My Code Is:

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)

It Would Be A Great Help If You Reolve This.

2
Please show the whole stack trace. - kaya3

2 Answers

0
votes
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)

Try this

0
votes

You made two small mistakes, but your code was almost correct:

  • you need to remove .find after BeautifulSoup, as this line is made just for creating the soup but not searching anything
  • you need to use .text instead of .content when retrieving the request, as BeautifulSoup works with strings rather than bytes.

Here is the final code:

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)