Here is my Duck Duck Go search script.
import duckduckgo
r = duckduckgo.query('DuckDuckGo')
print r.results[0].url
it returns; list index out of range. If i print r.results i get;
[<duckduckgo.Result object at 0x0000000002E98F60>]
But if i search for anything other than 'DuckDuckGo'. It returns an Empty value
[]
I havefollowed exactly what they did in the example code. https://github.com/mikejs/python-duckduckgo
That is documented behaviour. There are different result attributes.
Your first query returns a list of results.
r = duckduckgo.query('DuckDuckGo')
if r.type == 'answer':
print r.results # [<duckduckgo.Result object>]
Your other search returns a disambiguation and your results are in r.related
not in r.results
r = duckduckgo.query('Python')
if r.type == 'disambiguation':
print r.related # [<duckduckgo.Result object>]
Edit: python-duckduckgo uses the DuckDuckGo API which does not give you all the search result links
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.
You can't do what you want to do using the DuckDuckGo API but a possible workaround has been posted on Stackoverflow: https://stackoverflow.com/a/11923803/241866
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With