add redirect support

This commit is contained in:
Maks Snegov 2013-11-10 00:15:30 +04:00
parent 67b7dc81e9
commit fe61491292

View File

@ -28,6 +28,11 @@ def get_page(url):
conn.request("GET", up.path, None, headers) conn.request("GET", up.path, None, headers)
response = conn.getresponse() response = conn.getresponse()
if (response.status == http.client.MOVED_PERMANENTLY) \
or (response.status == http.client.FOUND):
new_url = response.getheader('Location')
print('Redirect to ' + new_url)
return get_page(new_url)
# get page charset from response header # get page charset from response header
contenttype = response.getheader('Content-Type') contenttype = response.getheader('Content-Type')