我试图从这个webpage中获取不同的产品名称。产品名称(如0041-5053-005
)动态生成。但是,我可以使用带有适当参数的xhr来刮取它们
有必要在标题中使用以下键和值来获取所需的数据
headers = {
'client_secret': '',
'client_id': '',
'correlation_id': '0196e1f2-fb29-0modod-6125-fcbb6c2c69c1',
}
以下是我如何摘取标题的:
import requests
link = "https://es-be-ux-search.cloudhub.io/api/ux/v2/search?"
payload = {
'queryText': '*:*',
'role': 'rockwell-search',
'spellingCorrect': 'true',
'spellcheckPremium': '10',
'segments': 'Productsv4',
'startIndex': 0,
'numResults': 10,
'facets': '',
'languages': 'en',
'locales': 'en_GLOBAL,en-US',
'sort': 'cat_a',
'collections': 'Literature,Web,Sample_Code',
'site': 'RA'
}
with requests.Session() as s:
r = s.get(link,params=payload,headers=headers)
for item in r.json()['response']['docs']:
print(item['catalogNumber'])
我注意到client_secret
和client_id
的值是静态的,但是correlation_id
的值发生了变化
How can I use the value of
correlation_id
within the headers without hardcoding?
关联ID用于关联客户端和服务器之间的HTTP请求See this article for details on how that works。似乎此API要求相关ID出现在HTTP头中,但不会根据其值更改响应。如果给出空字符串,则响应相同:
相关问题 更多 >
编程相关推荐