3 Requests
1 请求
1.1 发起网络请求
GET请求:
import requests
# GET请求
response_get = requests.get('http://www.baidu.com')
char_data = response_get.text # 字符串响应数据
binary_data = response_get.content # 二进制响应数据
# 可以对binary_data进行对应的数据解码
binary_data.decode('utf-8')
# POST请求
response_post = requests.post('http://httpbin.org/post',data={
'key':'value'})
# put 请求
response_put = requests.put('http://httpbin.org/put',data={
'key':'value'})
# delete 请求
response_delete = requests.delete('http://httpbin.org/delete')
# head 请求
response_head = requests.head('http://httpbin.org/head')
# options 请求
response_options = requests.options('http://httpbin.org/options')
1.2 传递参数
import requests
params = {
'key1':'value1','key2'