Duckduckgo API getting search results

api, duckduckgo-api

What I want to do is 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).

I have asked a similar question ( Python search scraping) and the answer to it works well with google my problem is that I can't find Duckduckgo's search api address anywhere. Could you help me or suggest antoher way of doing this?

Best Solution

tl;dr -- Screen scrape https://duckduckgo.com/html/?q={search_terms}

As other answerers have mentioned, the URL for DuckDuckGo's limited search API is

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

x being the search terms you're looking for.

However, please note that this is not a full search API. As DuckDuckGo's API page mentions,

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.

So for your stated purpose of

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 will not get you what you want.

Your best bet is probably to just screen scrape the non-JS, web version of DuckDuckGo:

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

looking for elements with a selector of something like div.result or div.web-result.