Replies: 3 comments 2 replies
-
|
Hi @Jelzap0, I ran into the same HTTPError: HTTP Error 403: Forbidden with pd.read_html(URL) (Wikipedia blocks pandas’ default urllib user-agent). Fix: fetch the page with requests using a browser-like header, then pass the HTML to read_html: Optional (only if you see SSL certificate errors): Tip: if you’re in a notebook, restart the kernel and run from the top after changes. Happy coding 😎 |
Beta Was this translation helpful? Give feedback.
-
|
There's maybe a bit too much code in that solution, and I feel using requests (although fine) is not something I would use here especially when we have gazpacho at our disposal. I'd replace this line in the notebook:
with these lines of code (which effectively tricks Wikipedia into responding as Wikipedia believes it is talking to a recent Chrome browser): As stated above, Wikipedia is trying to discourage web scraping with Python (pandas), which is a pity as I feel the usage discussed in the book is valid and reasonable. That said, I guess it's their site and Wikipedia can run it how they like. Note that pandas currently has no way to specify the ID of the User-Agent (the browser) which is why we're doing things as shown in the above code. The use of the IO standard library converts the returned HTML into a format read_html can use, otherwise read_html thinks the string is a filename, can't find it when it goes looking for it, then crashes with an IOError. Using the conversion shown above fixes this issue. Regards, and thanks. --Paul. |
Beta Was this translation helpful? Give feedback.
-
|
@headfirstpython @AAdewunmi |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
In chapter 9½ page 430, when doing
It gives
HTTPError: HTTP Error 403: Forbidden.Here the complete traceback:
Beta Was this translation helpful? Give feedback.
All reactions