urllib 和urllib2都是接受URL请求的相关模块,但是提供了不同的功能。两个最显著的不同如下:
urllib2can accept aRequestobject to set the headers for a URL request,urllibaccepts only a URL. That means, you cannot masquerade your User Agent string etc.urllib2可以接受一个Request类的实例来设置URL请求的headers,urllib仅可以接受URL。这意味着,你不可以伪装你的User Agent字符串等。
urllibprovides theurlencodemethod which is used for the generation of GET query strings,urllib2doesn't have such a function. This is one of the reasons whyurllibis often used along withurllib2.urllib提供urlencode方法用来GET查询字符串的产生,而urllib2没有。这是为何urllib常和urllib2一起使用的原因。
转载于http://www.cnblogs.com/yuxc/archive/2011/08/01/2124073.html
本文详细介绍了Python中urllib与urllib2模块的主要区别。urllib2可以通过Request对象设置URL请求的headers,而urllib只能直接使用URL。此外,urllib提供了urlencode方法用于生成GET查询字符串,而urllib2没有此功能。
200

被折叠的 条评论
为什么被折叠?



