16

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 Answers 6

9

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.

9

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
    Commented Apr 5, 2023 at 12:44
3

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. Commented Dec 10, 2019 at 4:16
1

In our monitoring platform, we rely on such "lucky" URLs mainly for the identification of disk drive models by their product number e.g. KCD8XPUG3T84

While the suggested answers worked well in the past, in 2024 even the DuckDuckGo solution is not behaving as expected.

Hence we've built: https://lucky.surf/ initially for our internal use, but we're opening it up for the world as of today.

How to use it? One way would be to, simply append your search parameter in the URI eg.

Disclaimer: lucky.surf is a product developed by us, and it is directly affiliated with BlackHOST

1
  • If you want to recommend your own product or website, there are some guidelines in place for doing so. Following them will help you avoid giving the impression that you're spamming. Please edit your post to explicitly state your affiliation. (If you're not actually affiliated, it may be worth mentioning that as well.) Commented Feb 29 at 14:38
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.

-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 and acknowledge you have read our privacy policy.

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