python3.x requests 模塊使用
阿新 • • 發佈:2018-06-22
IV In headers .com orm data com 狀態 print
使用時換成具體的url,key和value即可
import requests import json # GET url = ‘http://www.baidu.com‘ params = {‘key‘: ‘value‘} headers = {‘key‘: ‘value‘} cookies = {‘key‘: ‘value‘} response = requests.get(url, params=params, headers=headers, cookies=cookies) print(response.text) # 返回的文本 print(response.json()) #返回的json數據 print(response.status_code) # 返回狀態碼 #POST url = ‘http://www.baidu.com‘ # form params = {‘key‘: ‘value‘} response = requests.post(url, data=params) # json payload = {‘key‘: ‘value‘} response = requests.post(url, json=json.dumps(payload)
python3.x requests 模塊使用