1. 程式人生 > >python3.x requests 模塊使用

python3.x requests 模塊使用

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 模塊使用