Python: difference between urllib and urllib2
来源:互联网 发布:sql server数据库知识 编辑:程序博客网 时间:2024/06/07 03:59
What is the difference between urllib and urllib2 modules of Python?
You might be intrigued by the existence of two separate URL modules in Python - urllib
andurllib2
. Even more intriguing: they are not alternatives for each other. So what is the difference between urllib
and urllib2
, and do we need them both?
urllib
and urllib2
are both Python modules that do URL request related stuff but offer different functionalities. Their two most significant differences are listed below:
urllib2
can accept aRequest
object to set the headers for a URL request,urllib
accepts only a URL. That means, you cannot masquerade your User Agent string etc.urllib
provides theurlencode
method which is used for the generation of GET query strings,urllib2
doesn't have such a function. This is one of the reasons whyurllib
is often used along withurllib2
.
For other differences between
urllib
and urllib2
refer to their documentations, the links are given in the References section.Tip: if you are planning to do HTTP stuff only, check out httplib2, it is much better than httplib or urllib or urllib2.
Exercise
- What is User Agent?
- What is the difference between GET and POST request methods?
- What is HTTP?
References
- urllib
- urllib2
0 0
- Python: difference between urllib and urllib2
- What is the difference between urllib and urllib2 modules of Python?
- Difference between Python 2 and Python 3
- urllib and urllib2
- python urllib/urllib2应用
- python urllib diff urllib2
- Python urllib2 urllib学习
- python urllib与urllib2
- python urllib2, urllib使用
- python-urllib/urllib2
- Python urllib&urllib2&httplib
- Difference between __str__ and __repr__ in Python
- Difference between Range and Xrange in Python
- The difference between Python __init__ and __new__
- Difference between Scopes and Namespaces in python
- The difference between (()) and ().
- difference between "<" and "<<"
- Python 的 urllib,urllib2,httplib
- UML基础: 统一建模语言简介
- yum 安装时错误 Errno 14 Couldn't resolve host 解决办法
- Android 高仿 频道管理----网易、今日头条、腾讯视频 (可以拖动的GridView)附源码DEMO
- android 软键盘的显示与隐藏问题的研究
- bea tuxedo中间件入门
- Python: difference between urllib and urllib2
- ZOJ-2972
- 【Coding】 动规, 这个, 逻辑不严谨呀同学, 多多练习。
- 子主窗口间消息发送
- 远离共享安全问题 FTP共享文件自己做
- VC 按钮添加提示
- android fragmnet
- GDB使用入门
- Android:对service的一点理解1