• 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”

  • 相关阅读:
    使用JAX-WS(JWS)发布WebService(一)
    PING命令与ICMP协议
    子网划分和无分类编址
    谈谈网络分层和IP
    hydra暴力破解ssh服务器密码
    TCP报文解析
    OSI七层协议与TCP连接
    Java Native Interface调用C++代码
    Java的序列化和反序列化
    Java关于static的作用
  • 原文地址:https://www.cnblogs.com/qiaoer1993/p/10777957.html
Copyright © 2020-2023  润新知