问题
I have this python request code that works but I don't understand what the parameters represent. I want to understand how the set parameters for python request and if there is a good reference for this. Here is the code i use
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()
I understand most of the code but don't really understand these attributes of param
'cat_id': 0,
'ps': 24,
'offset': 0,
could anyone please explain provide an explanation for this and how to set parameters for python request
回答1:
Parameters that you pass into requests are specific to the URL
you are making the request to. Whatever parameters you specify has a reason for its existence and they can often be located in the API
documentation.
In this case(as provided by @chillie), they represent:
cat_id - Category on Walmart Search. (e.g. 0 (default) is all departments, 976759_976787 is 'Cookies', etc.). Either a query or a cat_id parameter is required.
ps- Determines the number of items per page. There are scenarios where Walmart overrides the ps value. By default Walmart returns 40 results.
Offset - offset value is often used to increment by x each api call, (ex. offset = x+1000, offset = x+2000, offset = x+3000, etc) until all pages retrieved.
来源:https://stackoverflow.com/questions/63993790/python-how-to-set-parameters-for-python-request