【发布时间】:2019-06-18 08:50:53
【问题描述】:
我正在尝试发送 ajax 请求并获取 json 数据,但我收到了 400 Bad request
我尝试过传递不同的标头,但还是不行
import requests
import json
headers = {"Host": "www.zalando-prive.it",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0",
"Accept": "application/json, text/plain, */*",
"Accept-Language": "en-US",
"Accept-Encoding": "gzip, deflate, br",
"X-Requested-With": "XMLHttpRequest",
"Referer":"https: //www.zalando-prive.it/campaigns/ZZLPH1"
}
data = {"filter": {},
"sort": "attractivity",
"gender": "FEMALE",
"page": 1}
url = "https://www.zalando-prive.it/api/campaigns/ZZLPH1/articles"
response = requests.get(url, data=data, headers=headers)
print(response.text)
您的浏览器发送了一个此服务器无法理解的请求,而我希望得到 json 响应
【问题讨论】:
-
尝试用
params=data替换data=data然后检查。除非您描述填充 json 响应的步骤,否则不清楚您要做什么。
标签: python ajax parsing web-scraping python-requests