14

I'm looking for an URL that goes directly to the first Google hit from a certain domain as in "I'm Feeling Lucky" but limited to a certain domain.

I'm using this formula, but it typically doesn't work.

http://www.google.com/search?q=SEARCHTERM%20site:SITEURL&btnI

Edit: It seems to work a lot of the time actually. However, there are quite a few cases in which it will not work.

5 Answers 5

7

Use links like https://www.google.com/search?btnI=1&q=%s site:developer.mozilla.org

btnI=1 makes the difference from a normal request.

7

I solved this by switching to an equivalent service by another search engine.

While the formula given in the question often works, Google will sometimes chicken out and go to a regular search results page rather than going directly to the top hit.

DuckDuckGo never chickens out. It always goes to the top hit.

Therefore I am using DuckDuckGo for this particular service from now on.

Here is the formula for DuckDuckGo:

https://duckduckgo.com/?q=!ducky+searchterm+site%3Asiteurl

For example:

 https://duckduckgo.com/?q=!ducky+LOL%20Cats+site%3Ayoutube.com

This is where I learned it, by the way.

1
  • This doesn't work as a link from an external site.
    – Semra
    Apr 5 at 12:44
2

In my experience, using an ordinary "btnI=1&q=" Google URL worked fine in the past. But for a few years I've been experiencing unreliable "lucky" redirects, as noticed by the poster of this question. After some troubleshooting I discovered that one can fix this with a "Referer: http://www.google.com/" header:

w3m -header "Referer: http://www.google.com/" "http://www.google.com/search?ie=ISO-8859-1&hl=en&source=hp&q=happy+nation+lyrics&btnI=I%27m+Feeling+Lucky&gbv=1"

For me, removing the header parameter in the above command causes the redirect not to work. Redirect also breaks if you remove the "www." in the "http://" URL.

I figured this out by comparing the URLs and headers in the HTTP requests generated by manually clicking on the "Lucky" button vs loading the URL directly. https://serverfault.com/questions/504431/human-readable-format-for-http-headers-with-tcpdump (Unfortunately this snooping method only works with HTTP, not HTTPS)

1
  • As of October 2019, "Google lucky" URLs sometimes produce a special redirect page, for me at least, that needs extra parsing to get the URL of the top result. I just wrote a script which does this, but it is not very elegant. Dec 10, 2019 at 4:16
0

Use this one (Twitter as example, you change this to your search words)

http://www.google.com/search?q={twitter}&btnI

To stop the redirect notice use this small extension.

-2
http://www.google.com/search?q={query}&btnI

Try this one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.