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
评论列表
文章目录