headers={
‘Content-Type’: ‘application/x-www-form-urlencoded; charset=GBK’,
‘User-Agent’: ‘Dalvik/1.6.0 (Linux; U; Android 4.4.2; M6 Note Build/N2G47H)’,
‘Host’: ‘app.bidchance.com’,
‘Accept’: ‘/’,
‘Connection’: ‘Keep-Alive’,
‘Accept-Encoding’: ‘gzip’,
‘Content-Length’: ‘193’,
}
data={“timestamp”: “2018-10-09 15:00:05:214”, “field”: “all”, “keywords”: “\u7535\u68af”, “apiToken”: “2ca0ef95a12c79f367b9857e356e06fb”, “userToken”: “214b3f092fa11310cf54a4817a8529da”, “province”: “”, “currentPage”: “1”, “datasource”: “”}
url = ‘http://app.bidchance.com/app/search’
r = requests.post(url,headers=headers,data=data,verify=False)
a = r.text
print(a)
错误1:data=json.dumps(data)请求页面,导致一直请求失败。修改为data=data即可。
正确:r = requests.get(url,headers=headers,data=data,verify=False)
修改了以上之后,还是报错。最后发现该请求是一个post请求并非get。
正确:r = requests.post(url,headers=headers,data=data,verify=False)
3.对于data,除了在Header中取url?后面的部分构造(get请求),也可以在webForms中找到(post请求)