Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duckduckgo API getting search results [duplicate]

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?

like image 572
Nesa Avatar asked May 03 '16 19:05

Nesa


People also ask

Where does DuckDuckGo get their search results?

DuckDuckGo uses its web crawler, DuckDuckBot, and up to 400 other sources to compile its search results, including other search engines like Bing, Yahoo, and Yandex, and crowdsourcing sites like Wikipedia.

Is DuckDuckGo a good search engine?

DuckDuckGo is fairly safe and offers much more privacy than mainstream browsers. First of all, DuckDuckGo's main appeal is your search privacy. This means that DuckDuckGo doesn't collect user data and track your search history. Unlike Google, it doesn't associate what you look for online with your IP address.

Does DuckDuckGo have an API?

The DuckDuckGo Instant Answer API provides free programmatic access to many of the search engine’s instant answers, pulled from over 100 independent sources. Answers include things like topic summaries, categories, disambiguation, redirects, and definitions.

How do you increase DuckDuckGo search results?

To gain the best local results from DuckDuckGo users, you should use hyperlocal terms in your site, describing where you are, what's nearby, major intersections, roads, neighborhoods, and other regions that a user might input when they are searching for a local result.


2 Answers

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.

like image 112
ethanbustad Avatar answered Oct 20 '22 04:10

ethanbustad


just change with whatever you want to search for. This will output the results in JSON

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

I think this is what you are asking for

like image 20
Steve Avatar answered Oct 20 '22 05:10

Steve