Snippet Get Web Page in Python
TODO: Update this with the other post for `requests`
TODO: I think this is a duplicate post. Need to remove one or the other if that's the case.
Here's the simple snippet I use to scrape basic web pages in Python.
return
return
Most of the examples I see only have the middle part:
return
The problem is that code crashes if the server sends an error code back. Wrapping it with the try lets you handle that.
Here's a full sample:
#!/usr/bin/env python3
return
return
=
-- end of line --