python 面对ajax请求数据如何获取?
本帖最后由 double07 于 2021-5-12 12:01 编辑想获取链接(https://sf-item.taobao.com/sf_item/641634330827.htm?spm=a213w.7398504.paiList.1.52bd533aQrsYmj&track_id=2151e118-70ef-4958-bfe3-24d7937454ff)所有竞买记信息(共73条),对页面分析为ajax请求,找到竞买信息的数据及请求链接,并对链接进行requests请求,发现无数据返回,请问如何自动获取ajax请求链接及链接对应73条记录?
url = 'https://sf-item.taobao.com/json/get_bid_records.htm?currentPage=2&_ksTS=1620740116592_604&callback=jsonp605&id=641634330827&records_type=pageRecords'
headers = {
'Referer': 'https://sf-item.taobao.com/sf_item/641634330827.htm?spm=a213w.7398504.paiList.1.52bd533aQrsYmj'
'&track_id=2151e118-70ef-4958-bfe3-24d7937454ff'
}
response = requests.get(url=url,headers=headers).text
print(response) 本帖最后由 double07 于 2021-5-11 22:28 编辑
laos 发表于 2021-5-11 21:45
url = 'https://sf-item.taobao.com/json/get_bid_records.htm?currentPage=2&_k ...
谢谢,但这只是获取的部分信息,如要自动捕获ajax请求链接并获取所有记录信息,有什么思路? double07 发表于 2021-5-11 21:53
谢谢,但这只是获取的部分信息,如要自动捕获ajax请求链接并获取所有记录信息,有什么思路?
currentPage=2
这是获取第二页 可替换相应的页数 本帖最后由 szx666 于 2021-5-11 23:18 编辑
import requests
import json
url = 'https://sf-item.taobao.com/json/get_bid_records.htm?_ksTS=1620740116592_604&callback=jsonp605&id=641634330827&records_type=pageRecords¤tPage='
headers = {
'Referer': 'https://sf-item.taobao.com/sf_item/641634330827.htm?spm=a213w.7398504.paiList.1.52bd533aQrsYmj'
'&track_id=2151e118-70ef-4958-bfe3-24d7937454ff'
}
def a(pageB):
response = requests.get(url=url + str(pageB), headers=headers).text
d = response
response = response.replace(d, '')
response = response.replace('(', '')
response = response.replace(')', '')
response = response.replace('totalCnt', '"totalCnt"')
response = response.replace('records', '"records"')
response = response.replace('alias', '"alias"')
response = response.replace('date', '"date"')
response = response.replace('price', '"price"')
response = response.replace('bidTime', '"bidTime"')
response = response.replace('formatePrice', '"formatePrice"')
response = response.replace('status', '"status"')
response = response.replace('isSelf', '"isSelf"')
response = response.replace('ceilingPriceBid', '"ceilingPriceBid"')
response = response.replace('priorityUser', '"priorityUser"')
b = json.loads(response)['records']
c = len(b) - 1
if c != -1:
print(b)
pageB += 1
a(pageB)
else:
print('打印完成')
a(1)
凑合着看吧,大概就是这个意思 思路来了,重新构建ajax请求的链接,翻页的问题用取商的方式解决
页:
[1]