def getUnRedirectUrl(url,timeout=10):
req = urllib2.Request(url)
debug_handler = urllib2.HTTPHandler(debuglevel = 0)
opener = urllib2.build_opener(debug_handler, RedirctHandler)
html = None
response = None
try:
response = opener.open(url,timeout=timeout)
html = response.read()
except urllib2.URLError as e:
if hasattr(e, 'headers'):
error_info = e.headers
elif hasattr(e, 'reason'):
error_info = e.reason
finally:
if response:
response.close()
if html:
return html
else:
return error_info
评论列表
文章目录