urllib2定义的函数:
1、urllib2.urlopen(url[, data[, timeout[, cafile[, capath[, cadefault[, context]]]]])
用来发送request请求,现在我只用到了前两个参数,后边几个参数后面慢慢了解以后再来谈论
1.1 使用urllib2.urlopen(url) 向web服务提交GET请求
1.2 使用urlib2.urlopen(url,data) 向web 服务提交POST请求
这个方法返回一个类文件
对象,可以像使用read() 读取文件内容一样,使用read() 方法读取该对象的值,读完以后对象将被置空,所以只能读一次,再此读取就获取不到任何内容了
此外该对象还定义了另外三个函数来获取http请求影响的内容,geturl() — return the URL of the resource retrieved, commonly used to determine if a redirect was followed
info() — return the meta-information of the page, such as headers, in the form of an mimetools.Message instance (see Quick Reference to HTTP Headers)
getcode() — return the HTTP status code of the response.
python之urllib2的用法
最新推荐文章于 2022-02-08 17:21:57 发布