#!/usr/bin/env python # -*- coding: utf-8 -*- import requests import csv import json def test(): f = open("D:/YMM/pythonscript/hyr/file/dmpt个人任务.csv", mode="w", encoding="gbk", newline="") # newline="" 去除换行 csvwriter = csv.writer(f) head_name = ["需求ID", "需求名称", "状态"] # xls表头 csvwriter.writerow(head_name) userid = {100,200.300,400} for ids in userid: url = "https://xxxxx.com/resUser/getScheduleDataByUserId?userId=" + str( ids) + "&isDevChecked=true&isTestChecked=true" \ "&isTempChecked=true " headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/97.0.4692.99 Safari/537.36", "Cookie":"ajkadaiodiaodoiaods", "Content-Type": "application/json;charset=UTF-8"} resp = requests.get(url, headers=headers, verify=False) content = resp.text data = json.loads(content) child_data_list = data["data"]["trs"] for i in range(len(child_data_list)): task = child_data_list[i] reqId = task['reqId'] reqName = task['reqName'] reqStatusName = task['reqStatusName'] csvwriter.writerows([(reqId, reqName, reqStatusName)]) # 写入多行writerows f.close() if __name__ == '__main__': test()