Extractor.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:Extractor 作者: llq007 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号