is_google_connect.py 文件源码

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

项目:auto-laod-hosts 作者: yanjinyi1987 项目源码 文件源码
def urlopen_test(host):
    headers = [('Host',host),
    ('Connection', 'keep-alive'),
    ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
    ('User-Agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0'),
    #('Accept-Encoding','gzip,deflate'), 
    ('Accept-Language', 'en-US,en;q=0.5')]

    #????MozillaCookieJar???????cookie
    cookie=cookielib.MozillaCookieJar()
    handler=urllib2.HTTPCookieProcessor(cookie)

    req=urllib2.Request(u'https://'+host)
    first_opener = urllib2.build_opener(handler)
    first_opener.addheaders = headers
    try:
        result=first_opener.open(req,timeout=60) #60s??
        if result.read()!=None:
            return True
    except Exception,e:
        print e
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号