Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replicate Google's "I'm Feeling Lucky" Button On My Own Site -- To Take User to Top Search Result Automatically

I am trying to replicate Google's I'm feeling lucky button.

But when I click the button it takes me to " Redirect Notice" page.

My code is as below:

<form action="https://google.com/search">
    <input type="text" name="q">
    <input type="submit" value="Google Search">
    <input type="submit" name = btnI value="I'm Feeling Lucky">
</form>
like image 434
Laxmikant Raikar Avatar asked Oct 26 '25 07:10

Laxmikant Raikar


1 Answers

TLDR: Just use DuckDuckGo. You typically don't care about what search engine is doing the redirecting, so long as you land on the top-result for a search term and the page for that result loads (and not a redirect page of the search engine).

https://duckduckgo.com/?q=%5Csoybeans

This URL above will redirect to...

https://en.wikipedia.org/wiki/Soybean

The %5c code above is the indicator for loading the page directly without search results (similar to the BtnI of Google).

Details on the Redirect Page from Linking to Google's "I'm Feeling Lucky"

  • Oct. 2, 2019: The redirect page was first reported on Google Search Help, the question has since been closed and comments are disabled -- they are probably not going to fix this.

  • You cannot use an <iframe />. Loading <iframe src="https://www.google.com/" /> has always loaded blank for me for the past ten years.

  • Likewise, you cannot use XMLHttpRequest, which I just tried, because CORS will block you out, and most browsers do not allow XMLHttepRequest.setHeader("origin", "http://www.google.com/");, otherwise, you could simply get the redirect page, parse for the first URL, and load that page. We know this is the case, because doing this following in a terminal will bypass the redirect page (thanks to Metamorphic for discovering this):

    w3m -header "Referer: http://www.google.com/" "https://www.google.com/search?btnI=1&q=soybeans"
    

Iframes don't work, XmlHttpRequest doesn't work, and the main post on the Google Search forums for this topic has been closed and locked. I think it's obvious you'll need to find a different approach -- i.e., like a different search engine.

like image 157
HoldOffHunger Avatar answered Oct 28 '25 20:10

HoldOffHunger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!