Reputation: 351
How can I get with urllib2 content of page sent with 403 Forbidden ? In real browser I'm receiving customized 403 page, but urllib2 throws exception.
Upvotes: 0
Views: 61
Reputation: 4781
I strongly suggest you use requests instead of urllib2 if possible, it will make your life better.
Anyway since you asked for urllib2 specifically, here's how:
try:
response = urllib2.urlopen('http://www.example.com')
except urllib2.HTTPError as exc:
if exc.code == 403:
content = exc.read()
The content
variable will hold the HTML source of the 403 page.
Upvotes: 1