我正在使用 Bing Web Search API 在 Bing.com 中搜索一些信息。但是,对于某些搜索查询,我从搜索中获取了与我的目的无关的网站。
例如,如果搜索查询是今年夏天要阅读的书籍, Bing 有时会返回youtube.com
或amazon.com
作为结果。但是,我不想在我的搜索结果中出现这类网站。所以,我想在搜索开始之前屏蔽这些类型的网站。
这是我的示例代码:
params = {
"mkt": "en-US",
"setLang": "en-US",
"textDecorations": False,
"textFormat": "raw",
"responseFilter": "Webpages",
"q": "books to read this summer",
"count": 20
}
headers = {
"Ocp-Apim-Subscription-Key": MY_APY_KEY_HERE,
"Accept": "application/json",
"Retry-After": "1",
}
response = requests.get(WEB_SEARCH, headers=headers, params=params, timeout=15)
response.raise_for_status()
search_data = response.json()
search_data变量包含我想要阻止的链接,而不需要对响应对象进行迭代。特别是,我希望 Bing 不要在结果中包含 youtube 和 amazon。
任何帮助将不胜感激。
编辑:WEB_SEARCH是网络搜索端点