URllib2 和 URLLib 区别的场合
urllib2
can accept a Request
object to set the headers for a URL request
urllib2可以接受一个Request对象,并以此可以来设置一个URL的headers
urllib
accepts only a URL
urllib只接收一个URL
urllib
provides the urlencode
method which is used for the generation of GET query strings
urllib 提供 urlencode方法 它被用作 GET 查询字符串的 生成
urllib2模块定义的函数和类用来获取URL(主要是HTTP的)
操作打开网页的数据
urllib2.
urlopen
(url[, data[, timeout[, cafile[, capath[, cadefault[, context]]]]])
data : 默认get 参数,当有数据时,打开post请求 The urllib.urlencode()
function takes a mapping or sequence of 2-tuples and returns a string in this format
timeout: 代表 阻塞操作以秒为单位
The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attemp
运用场合:HTTP, HTTPS and FTP connections.
urllib.
urlencode
(query[, doseq])
Convert a mapping object or a sequence of two-element tuples to a “percent-encoded” string
功能:转化成一个映射对象,或则由两个元素组成的元组 转化成“百分号编码”字符串
将URL中的键值对以连接符&划分
This is useful to pass a dictionary of form fields to a POST
request