使用 BING 网络搜索 API 进行基于 Python 的 PDF 搜索

问题描述 投票:0回答:2

我想使用 bing API 从关键字检索相关的 pdf。但我面临一些问题。

关键词列表:

"Hubble Space Telescope", "William Herschel", "Planetary Camera", "Milky Way"

我正在遵循此代码:

 import requests

subscription_key = "My Key"
assert subscription_key

search_url = "https://api.cognitive.microsoft.com/bing/v7.0/search"
search_term = ["Hubble Space Telescope", "William Herschel", "Planetary Camera", "Milky Way"]

result=[]
for i in range(len(search_term)):
    headers = {"Ocp-Apim-Subscription-Key" : subscription_key}
    params  = {"q": search_term[i],"filetype":"pdf", "textDecorations":True, "textFormat":"HTML"}
    response = requests.get(search_url, headers=headers, params=params)
    response.raise_for_status()
    search_results = response.json()
    print search_results
    result.append(search_results)


from IPython.display import HTML

for i in range(len(result)):
    rows = "\n".join(["""<tr><td><a href=\"{0}\">{1}</a></td><td>{2}</td>
                    </tr>""".format(v["url"].encode("utf-8"),v["name"].encode("utf-8"),v["snippet"].encode("utf-8")) \
                      for v in result[i]["webPages"]["value"]])

HTML("<table>{0}</table>".format(rows))

print rows

虽然我在参数部分添加了 filetype: pdf 但没有得到任何 pdf。

有人可以建议我如何继续吗?

python-2.7 bing-api
2个回答
0
投票

"filetype:pdf"
作为搜索词的一部分,而不是作为单独的查询字符串参数。


0
投票

添加 filetype:pdf 作为搜索词的一部分时,您将不会得到任何结果!

© www.soinside.com 2019 - 2024. All rights reserved.