Web Scraping Using Python And Beautiful Soup: Error "'page' Is Not Defined"
From a betting site, I want to collect the betting rates. After inspecting the page, I noticed that these rates were included into a eventprice class. Following the explanation fro
Solution 1:
If you print the exception details you will see what is happening:
try:
page = urllib.request.urlopen(url)
except Exception as e:
print(f"An error occurred: {e}")
Output
An error occurred: HTTP Error 403: Forbidden
Traceback (most recent call last):
File ".../main.py", line 12, in <module>
soup = BeautifulSoup(page, 'html.parser')
NameError: name 'page' is not defined
urlopen() is raising an Exception which results in an undefined 'page' variable. In this case it's a 403 which means you may need to add authentication in order to access this URL.
Update:
A 403 response means there is no way to access this URL in the way that you are trying to access it.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
Post a Comment for "Web Scraping Using Python And Beautiful Soup: Error "'page' Is Not Defined""