您的位置:首页 > 编程语言 > Python开发

urlib2下载器网页的三种方法

2016-04-03 21:44 417 查看
import urllib2
import cookielib

url = "http://wwww.baidu.com"

response = urllib2.urlopen(url)
print str(response.getcode()) + " "+ str(len(response.read()))

requset = urllib2.Request(url)
requset.add_header("user-agent","Mozilla/5.0")
response = urllib2.urlopen(requset)
print str(response.getcode()) + " "+ str(len(response.read()))

CKJR 	= cookielib.CookieJar()
HCKP = urllib2.HTTPCookieProcessor(CKJR )
OPENER 		= urllib2.build_opener(HCKP)
urllib2.install_opener(OPENER)
response = urllib2.urlopen(url)
print str(response.getcode()) + " "+ str(len(response.read()))
print CKJR
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python urllib2