我正在尝试使用 python 请求进行分页,但我似乎无法获取总页面,并且 JSON 响应不会随着页面的更改而更新。
url = 'https://www.walmart.com/store/1003-York-pa/search?query=ice%20cream'
api_url = 'https://www.walmart.com/store/electrode/api/search'
params = {
'query': word,
'cat_id': 0,
'ps': 24,
'offset': 0,
'prg': 'desktop',
'stores': re.search(r'store/(\d+)', url).group(1)
}
data1 = requests.get(api_url, params=params).json()
num_pages = data1['pagination']['pages'][-1]['page']
for page in range(0, num_pages + 1):
params = {
'query': word,
'cat_id': 0,
'page':page, // try to update the new page
'ps': 24,
'offset': 0,
'prg': 'desktop',
'stores': re.search(r'store/(\d+)', url).group(1)
}
data = requests.get(api_url, params=params).json()
我做错了什么,我该如何解决?
潇湘沐
相关分类