python中,urllib2中的urlopen()方法可以这样用:
response=urllib2.urlopen("http://www.baidu.com")
html=response.read()
也可以这样用:先创建一个Request对象
request=urllib2.Request("http://www.baidu.com")
response=urllib2.urlopen(request)
html=response.read()
查看urllib2.urlopen()方法:
urlopen(url, data=None, timeout=<object object>, cafile=None, capath=None, cadefault=False, context=None)
其中并没有Request类型的参数,但是为什么可以这样用呢?