Duckduckgo API 正在获取搜索结果

Duckduckgo API getting search results

我想做的只是提交字符串查询(相当于手动输入搜索栏)并保存第一个结果的 URL(如果有的话)。

我问过一个类似的问题 (),它的答案与 google 很相配,我的问题是我在任何地方都找不到 Duckduckgo 的搜索 api 地址。你能帮我或建议她这样做的方法吗?

只需更改为您要搜索的内容即可。这将在 JSON

中输出结果
https://api.duckduckgo.com/?q=<your search string>&format=json&pretty=1&no_html=1&skip_disambig=1

我想这就是你想要的

www.api.duckduckgo.com/?q=Search&format=json&pretty=1

示例: http://api.duckduckgo.com/?q=DuckDuckGo&format=json&pretty=1

响应是一个JSON对象,可以找到第一个link的地址:

response.Results[0].FirstURL

您可以通过将响应放入 https://jsonformatter.curiousconcept.com/

来找出答案

希望对您有所帮助:)

tl;dr -- 屏幕抓取 https://duckduckgo.com/html/?q={search_terms}

正如其他回答者提到的,DuckDuckGo 的 有限搜索 API URL 是

http://api.duckduckgo.com/?q=x&format=json

x 是您要查找的搜索词。

但是,请注意,这不是完整搜索API。正如 DuckDuckGo's API page 提到的那样,

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.

This is an Instant Answer API, and not a full results API. However, there are some Web links within it, e.g. official sites.

所以为了您所述的目的

just submitting string queries (the equivalent of typing into the search bar by hand) and saving the URL of the first results (if there are any).

api.duckduckgo.com不会得到你想要的。

你最好的选择可能只是屏幕抓取非 JS 网络版 DuckDuckGo:

https://duckduckgo.com/html/?q=x

寻找带有 div.resultdiv.web-result.

选择器的元素