在我的网站上复制谷歌的“我感觉很幸运”按钮——自动将用户带到顶部搜索结果

3

我正在尝试复制谷歌的“手气不错”按钮。

但是当我点击按钮时,它会将我重定向到“重定向通知”页面。

我的代码如下:

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

1
“name = btnI” 到底是什么意思?这是打错了吗? - Lelio Faieta
你确定一个表单中可以有两种类型的提交吗?只是一个问题... - Clément Tengip
2个回答

4

简短概述:只需使用DuckDuckGo。通常您不关心哪个搜索引擎进行重定向,只要您能以搜索词的顶部结果为目标,并且该结果的页面加载(而不是搜索引擎的重定向页面)即可。

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

上面的URL将重定向到...

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

上面的%5c代码是直接加载页面而不是搜索结果的指示符(类似于Google的BtnI)。

关于链接到Google的“我感觉幸运”页面的重定向页面的详细信息

  • 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不起作用,XmlHttpRequest也不起作用,而且关于这个问题的主要帖子在Google搜索论坛上已经关闭和锁定。我认为显然你需要找到另一种方法,比如使用其他搜索引擎。


-1
上面的%5c代码是直接加载页面而不是搜索结果的指示器(类似于Google的BtnI)。
我一直在到处寻找这个,谢谢!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接