2

我有这个有效的 python 请求代码,但我不明白参数代表什么。我想了解如何为 python 请求设置参数,以及是否有很好的参考。这是我使用的代码

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()

我了解大部分代码,但并不真正了解 param 的这些属性

'cat_id': 0,
'ps': 24,
'offset': 0,

谁能解释一下为此提供解释以及如何为python请求设置参数

4

1 回答 1

0

您传递给请求的参数特定于URL您发出请求的对象。您指定的任何参数都有其存在的原因,并且它们通常可以位于API文档中。

在这种情况下(由@chillie 提供),它们代表:

cat_id - 沃尔玛搜索上的类别。(例如,0(默认)是所有部门,976759_976787 是“Cookies”等)。需要查询或 cat_id 参数。

ps- 确定每页的项目数。在某些情况下,沃尔玛会覆盖 ps 值。默认情况下,沃尔玛返回 40 个结果。

偏移量 - 偏移值通常用于在每次 api 调用时增加 x,(例如,偏移量 = x+1000、偏移量 = x+2000、偏移量 = x+3000 等),直到检索到所有页面。

于 2020-09-21T17:43:00.163 回答