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”


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM