我有這個可以運行的 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 請求設置參數
1 回答

有只小跳蛙
TA貢獻1824條經驗 獲得超8個贊
您傳遞到請求中的參數特定于URL
您發出請求的對象。您指定的任何參數都有其存在的原因,并且它們通??梢栽?code>API文檔中找到。
在這種情況下(由@chillie提供),它們代表:
cat_id - 沃爾瑪搜索上的類別。(例如,0(默認)是所有部門,976759_976787 是“Cookies”等)。需要查詢或 cat_id 參數。
ps- 確定每頁的項目數。在某些情況下,沃爾瑪會覆蓋 ps 值。默認情況下,沃爾瑪返回 40 個結果。
Offset - 偏移值通常用于在每次 api 調用時增加 x(例如 offset = x+1000、offset = x+2000、offset = x+3000 等),直到檢索到所有頁面。
添加回答
舉報
0/150
提交
取消