Python 官方文档:入门教程 => 点击学习
[+] Httplib2功能介绍:http://code.Google.com/p/httplib2/ httplib2实例页面:http://code.google.com/p/httplib2/w/list httplib2问题
[+]
Httplib2功能介绍:http://code.Google.com/p/httplib2/
httplib2实例页面:http://code.google.com/p/httplib2/w/list
httplib2问题提交:http://code.google.com/p/httplib2/issues/list
好吧,我觉得官方的样例还是比较全的,这里就直接贴一下吧。
- import httplib2
- h = httplib2.Http(".cache")
- resp, content = h.request("http://example.org/", "GET")
- >>> from httplib2 import Http
- >>> from urllib import urlencode
- >>> h = Http()
- >>> data = dict(name="Joe", comment="A test comment")
- >>> resp, content = h.request("http://bitworking.org/news/223/Meet-Ares", "POST", urlencode(data))
- >>> resp
- {'status': '200', 'transfer-encoding': 'chunked', 'vary': 'Accept-Encoding,User-Agent',
- 'server': 'Apache', 'connection': 'close', 'date': 'Tue, 31 Jul 2007 15:29:52 GMT',
- 'content-type': 'text/html'}
- #!/usr/bin/env python
-
- import urllib
- import httplib2
-
- http = httplib2.Http()
-
- url = 'http://www.example.com/login'
- body = {'USERNAME': 'foo', 'PASSWORD': 'bar'}
- headers = {'Content-type': 'application/x-www-form-urlencoded'}
- response, content = http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))
-
- headers = {'Cookie': response['set-cookie']} ###将获得cookie设置到请求头中,以备下次请求使用
-
- url = 'http://www.example.com/home'
- response, content = http.request(url, 'GET', headers=headers) ##本次请求就不用带用户名,密码了
- import httplib2
- import socks ##需要第三方模块
-
- httplib2.debuglevel=4
- h = httplib2.Http(proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, 'localhost', 8000))
- r,c = h.request("http://bitworking.org/news/")
======================================================================================
下面是我自己对模块功能的尝试:
另外,httplib2模块本身还有其它的对象或属性,可以通过print dir(httplib2)来查看
--结束END--
本文标题: Python: httplib2模块
本文链接: https://www.lsjlt.com/news/188462.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0