GET
python
import requests
url ='https://finance.pae.baidu.com/vapi/stockshort'
params = {'code':'09888', 'market':'hk', 'finClientType':'pc' }
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, params=params, headers=headers)
print(response.status_code)
print(response.text)
POST
python
# 表单格式
import requests
url = 'https://example.com/api'
data = {'key1': 'value1', 'key2': 'value2'} # 表单数据
response = requests.post(url, data=data)
print(response.status_code)
print(response.json())
python
# json格式
import requests
url = 'https://example.com/api'
json_data = {'key1': 'value1', 'key2': 'value2'} # JSON 数据
headers = {'Content-Type': 'application/json'}
response = requests.post(url, json=data, headers=headers)
print(response.status_code)
print(response.json())