urlib2下载器网页的三种方法

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 

你可能感兴趣的:(urlib2下载器网页的三种方法)