【python】练习0608

2022/6/9 1:22:55

本文主要是介绍【python】练习0608,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

#!/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()

 



这篇关于【python】练习0608的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程