import urllib
import urllib2
murl = "http://zhpfbk.blog.51cto.com/"
UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2896.3 Safari/537.36"
req = urllib2.Request(murl)
req.add_header(‘User-Agent‘,‘Mozilla/5.0‘)
print req.get_method()
print req.get_full_url()
print req.get_host()
resp = urllib2.urlopen(req)
print resp.geturl()
print resp.read(50)
print resp.getcode()
本文出自 “Mask_X 博客” 博客,请务必保留此出处http://zhpfbk.blog.51cto.com/4757027/1886328
原文地址:http://zhpfbk.blog.51cto.com/4757027/1886328