繁体   English   中英

Bing API Advanced运算符,用于使用python进行网络搜索

[英]Bing api Advanced operator for web search using python

我想使用高级运算符来过滤搜索结果。 搜索结果应仅包含PDF。 我添加了高级运算符(文件类型:pdf)。 但似乎不起作用。

subscription_key = "My_ACCESS_KEY"
assert subscription_key
search_url = "https://api.cognitive.microsoft.com/bing/v7.0/search"
search_term = "NASA"
import requests

headers = {"Ocp-Apim-Subscription-Key" : subscription_key}
params  = {"q": search_term, "filetype":"pdf", "responseFilter":"Webpages", textDecorations":True, "textFormat":"HTML"}
response = requests.get(search_url, headers=headers, params=params)
response.raise_for_status()
search_results = response.json()

我不知道如何使用高级运算符( filetype:pdf )来过滤搜索结果。

有人可以建议我如何使用它吗?

谢谢

我只是尝试了他们文档中的示例代码。 我将filetype添加为url查询参数,并且似乎可以正常工作。

import requests

subscription_key = "..."
assert subscription_key

search_url = "https://api.cognitive.microsoft.com/bing/v5.0/search"

search_term = "Machine%20Learning&filetype=pdf"

headers = {"Ocp-Apim-Subscription-Key" : subscription_key}

params  = {"q": search_term}
response = requests.get(search_url, headers=headers, params=params)
response.raise_for_status()
search_results = response.json()

print(search_results)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM