zoukankan      html  css  js  c++  java
  • Python统计后台数据

    一、解析以下图片中返回值,并统计人员出现的次数。

    实现:获取Request Headers 、Request Payload,使用post请求即可。

    import requests
    
    def getDotData():
    
        url = "http://10.16.245.32:8080/testcase/getAllTestCases"
        headers = {
            "accept": "application/json",
            "Accept-Encoding": "gzip,deflate",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "access-control-allow-origin": "*",
            "Connection": "keep-alive",
            "Content-Length": "92",
            "content-type": "application/json;charset=utf-8;text/plain",
            "graytoken": "1",
            "Host": "10.16.245.32:8080",
            "Origin": "http://dot.dmall.com",
            "Referer": "http://dot.dmall.com/",
            "User-Agent": "Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/96.0.4664.45Safari/537.36"
        }
        data = {
                  "nodeId":"364ed45f",
                  "pageNum":1,
                  "pageSize":1000,
                  "dmallId":"tianpin.shen",
                  "name":"",
                  "tcId":""
        }
        req = requests.post(url=url, headers=headers, json=data).json()   # 要用json传参
        return req
    
    def resAllTestCase():
        myReq = getDotData()
        if 'E0000' == myReq['code']:
            data = myReq['data']
            if 'testCaseList' in data:
                testCaseList = data.get('testCaseList')
                myList = []
                myDict = {}
                for case in testCaseList:
                    creatorName = case.get('creatorName')
                    myList.append(creatorName)
                    for i in myList:
                        myDict[i]=myList.count(i)  # 统计列表中的人员出现次数,并添加在字典中
    
                        myDictSorted = sorted(myDict.items(), reverse=True, key=lambda item: item[1])  # 按照字典的value进行降序排列
    
                return myDictSorted
    
    
    if __name__ == '__main__':
        print(resAllTestCase())
    [('A', 111), ('B', 99), ('C', 96), ('D', 92), ('E', 90), ('F', 65), ('G', 18)]
  • 相关阅读:
    MVP模式与MVVM模式
    webpack的配置处理
    leetcode 287 Find the Duplicate Number
    leetcode 152 Maximum Product Subarray
    leetcode 76 Minimum Window Substring
    感知器算法初探
    leetcode 179 Largest Number
    leetcode 33 Search in Rotated Sorted Array
    leetcode 334 Increasing Triplet Subsequence
    朴素贝叶斯分类器初探
  • 原文地址:https://www.cnblogs.com/tianpin/p/15633170.html
Copyright © 2011-2022 走看看