獲取不到正確的requests請求結果
阿新 • • 發佈:2019-01-04
爬取過程中一直獲取到的結果和抓包獲取的不一樣,一直以為是頁面發生了跳轉,添加了allow_redirects=False,還是不對。使用fiddler抓包到的headers和data訪問也不對,最後換瀏覽器,還是不對,多次嘗試後,將data=data,居然拿到了正確的json
import json
import requests
headers = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate, br' ,
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Connection': 'keep-alive',
'Content-Length': '110',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookies':'hehe',
'Host': 'www.ll.com',
'Origin': 'https://www.lagou.com',
'Referer' : 'https://www.lau.com/dd/list_%E6%9D%AD%E5%B7%9E%E7%82%B9%E6%9C%9B%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8?labelWords=&fromSearch=true&suginput=',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36',
'X-Anit-Forge-Code' : '0',
'X-Anit-Forge-Token': 'None',
'X-Requested-With': 'XMLHttpRequest'
}
data = {
'first': 'false',
'pn': '5',
'kd': '杭州點點科技有限公司'
}
url = 'https://www.lau.com/dd/positionAjax.json?needAddtionalResult=false'
#一直請求下來的json和頁面看到的不一樣
# resp = requests.post(url,headers=headers,allow_redirects=False,data=data,verify=False)
resp = requests.post(url,headers=headers,data=data,verify=False)
print(resp.text)