zoukankan      html  css  js  c++  java
  • python爬取post请求Reque Payload的json数据

    import requests,json
    url = "https://www.xxxxxxxx"
    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Content-Type': 'application/json;charset=UTF-8',
        'Host': 'www.xxxx.com',
        'Referer': 'https://www.xxxx.com/',
        'token': 'xxxxxxxxx',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
        'Connection': 'keep-alive',
        'Content-Length': '320',
        'Origin': 'https://www.xxxxx.com',
    }
    payload = {"currentPage":1,"serviceTime":"2019-04-27 10:31:30","data":{"sonCategoryId":"3070","brandId":"","firstCategoryId":"","specialAreaId":"","categoryIds":["3070"],"brandIds":[],"isAscending":"","saleModel":-1,"searchModes":[],"sort":0,"shopId":"","currentPage":1,"pageSize":60},"pageSize":60,"addressId":1205414,"deviceType":3}
    #原生的payload为{"currentPage":1,"data":{"sonCategoryId":"3070","brandId":"","firstCategoryId":"","searchKey":null,"specialAreaId":"","categoryIds":["3070"],"brandIds":[],"labelId":null,"isAscending":"","saleModel":-1,"searchModes":[],"sort":0,"shopId":"","currentPage":1,"pageSize":60},"pageSize":60,"addressId":1205414,"deviceType":3} *********************这里需要把value为“null”的元素去掉,例如labelId":null,和"searchKey":null,(这里需要特别注意)
    response = requests.post(url=url,headers=headers,data=json.dumps(payload))
    text = response.text
    print(text)
    

      这里需要特别注意的是,把payload里面value为‘null’的值去掉(这里只是改url需要注意这一点,其他的还没测试),该url = “https://www.xxxxxxxxxxxxx”

  • 相关阅读:
    LeetCode#13罗马数字转整数
    LeetCode#7整数反转
    LeetCode#1两数之和
    LeetCode#26删除排序数组中的重复项
    LeecCode#1550存在连续三个奇数的数组
    LeetCode#228汇总区间
    LeetCode#1476子矩形查询
    LeetCode#1535找出数组游戏的赢家
    LeetCode#867转置矩阵
    Vue源码——摸着石头过河
  • 原文地址:https://www.cnblogs.com/qiaoer1993/p/10777957.html
Copyright © 2011-2022 走看看