问题遇到的现象和发生背景
用PYTHON 的 requests库请求一个post 状态码是200,但是返回内容是空。但同样的数据在fiddler 组合器,或者其它请求调试器 包括网页上找的中反回来JOSN。
得到的结果
另一个
网页上找的都可以
https://www.amazon.co.uk/gp/delivery/ajax/address-change.html
post
Host: www.amazon.co.uk
X-Requested-With: XMLHttpRequest
anti-csrftoken-a2z: gPEyD4jV7jHGbNAexAsKUIoQvXEwiNSOwFo3VfAAAAAMAAAAAGLPhJxyYXcAAAAA;hAQburVCSLlXy2uqtg9lK8QvCXBXwLD2A8Kfc6eVNr8pAAAAAGLPhJwAAAAB
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.49
Content-Length: 115
locationType=LOCATION_INPUT&zipCode=NG10+1PU&storeContext=generic&deviceType=web&pageType=Gateway&actionSource=glow
问题相关代码,请勿粘贴截图
import requests
import json
url = 'https://www.amazon.co.uk/gp/delivery/ajax/address-change.html'
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.49',
'viewport-width': '1278',
'Host': 'www.amazon.co.uk',
'Connection': 'keep-alive',
'X-Requested-With': 'XMLHttpRequest',
'anti-csrftoken-a2z': 'gPEyD4jV7jHGbNAexAsKUIoQvXEwiNSOwFo3VfAAAAAMAAAAAGLPhJxyYXcAAAAA;hAQburVCSLlXy2uqtg9lK8QvCXBXwLD2A8Kfc6eVNr8pAAAAAGLPhJwAAAAB',
'Content-Type': 'application/x-www-form-urlencoded',
}
data = {
'locationType': 'LOCATION_INPUT',
'zipCode': 'NG10 1PU',
'storeContext': 'generic',
'deviceType': 'web',
'pageType': 'Gateway',
'actionSource': 'glow',
'almBrandId': 'undefined'
}
zip_code = requests.post(url=url, headers=header, data=data)
print(zip_code.text)
print(zip_code.cookies)
运行结果及报错内容
我想要达到的结果
得到这个空的JOSN数据