10

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.

6

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.

4

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

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)

-3
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, privacy policy and cookie policy

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