gpt4 book ai didi

python - DuckDuckGo 搜索返回 'List Index out of range'

转载 作者:太空狗 更新时间:2023-10-30 03:03:41 35 4
gpt4 key购买 nike

这是我的 Duck Duck Go 搜索脚本。

import duckduckgo
r = duckduckgo.query('DuckDuckGo')
print r.results[0].url

它返回;列表索引超出范围。如果我打印 r.results 我得到;

[<duckduckgo.Result object at 0x0000000002E98F60>]

但是如果我搜索“DuckDuckGo”以外的任何内容。它返回一个空值

[]

我完全按照他们在示例代码中所做的操作。 https://github.com/mikejs/python-duckduckgo

最佳答案

documented behaviour .有不同的结果属性。

您的第一个查询返回结果列表。

r = duckduckgo.query('DuckDuckGo')
if r.type == 'answer':
print r.results # [<duckduckgo.Result object>]

您的其他搜索返回消歧义,您的结果在 r.related 中,而不是在 r.results

r = duckduckgo.query('Python')
if r.type == 'disambiguation':
print r.related # [<duckduckgo.Result object>]

编辑:python-duckduckgo 使用 DuckDuckGo API这不会给你所有的搜索结果链接

Our Instant Answer API gives you free access to many of our instant answers like: topic summaries (API example), categories (API example), disambiguation (API example), !bang redirects (API example), and definitions (API example).

This API does not include all of our links, however. That is, it is not a full search results API or a way to get DuckDuckGo results into your applications beyond our instant answers. Because of the way we generate our search results, we unfortunately do not have the rights to fully syndicate our results. For the same reason, we cannot allow framing our results without our branding. Please see our partnerships page for more info on guidelines and getting in touch with us.

您无法使用 DuckDuckGo API 做您想做的事,但 Stackoverflow 上已发布了一个可能的解决方法:https://stackoverflow.com/a/11923803/241866

关于python - DuckDuckGo 搜索返回 'List Index out of range',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18160464/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com