request库有很多功能,这里简单讲下post和get的功能,比直接使用urllib要方便一些
首先我们要安装requests库
然后很简单了,直接上代码
import requests
r = requests.get('http://httpbin.org/get')
print(r.text)
#post参数只需传递字典即可,不需要手动执行urlencode
r = requests.post('http://httpbin.org/post', data={'key': 'value'})
print(r.text)
r = requests.put('http://httpbin.org/put', data={'key': 'value'})
print(r.text)
r = requests.delete('http://httpbin.org/delete')
print(r.text)
r = requests.head('http://httpbin.org/get')
print(r.text)
r = requests.options('http://httpbin.org/get')
print(r.text)