使用python抽取post接口数据示例

postman调用接口post接口 https://inner-XXXXX.XXXXX.com/wXX/api/XXXXXctoryLake?user_key=XXXXXXXXXXXX,在boday的row里输入Jason格式的 {"wasStartDay":"2024-09-03"} 

使用python抽取post接口数据示例_第1张图片

import requests

url = 'https://inner-XXXXX.XXXXX.com/wXX/api/XXXXXctoryLake'
data = {"wasStartDay": "2024-09-03"}
params = {"user_key": "XXXXXXXXXXXX"}

response = requests.post(url, params=params, json=data)
json_data = response.json()

# 提取数据
rows = json_data['data']['rows']
insert_statements = []

for row in rows:
    userAccountNumber = row['userAccountNumber']
    loginNum = row['loginNum']
    lid = row['lid']
    visitDay = row['visitDay']
    deptFullName = row['deptFullName']

    # 拼接INSERT语句
    insert_statement = f"INSERT INTO your_table (userAccountNumber, loginNum, lid, visitDay, deptFullName) VALUES ('{userAccountNumber}', {loginNum}, '{lid}', '{visitDay}', '{deptFullName}');"
    insert_statements.append(insert_statement)

# 打印INSERT语句
for statement in insert_statements:
    print(statement)
 

你可能感兴趣的:(python,python,开发语言)