简体   繁体   English

自动点击搜索结果

[英]Automatically Click Search Results

This may be a very rookie error I am making, but my situation is this. 这可能是我犯的一个非常菜鸟错误,但我的情况是这样。 I have successfully made a script that when entered into a Google Chrome bookmark, it will bring up a prompt box upon the user clicking on the bookmark. 我已经成功创建了一个脚本,当该脚本输入Google Chrome书签时,将在用户单击书签时弹出一个提示框。 From there, after they hit enter, it brings said user to a list of search results. 从那里,在他们按下Enter键之后,它将把所述用户带到搜索结果列表。 What I want to do is put another piece of code in this same bookmark so that it automatically clicks on the first result on the search results page after it loads. 我想要做的是将另一段代码放在相同的书签中,以便它在加载后自动单击搜索结果页面上的第一个结果。 Any ideas? 有任何想法吗?

javascript: (function MCC() {
var feature = prompt('What is your search query?', '');
if (feature != null) {
    window.open('https://www.google.com/#q=' + encodeURIComponent(feature));
    window.onload = function MyClient() {
        document.getElementById('mHSB').click();
    }
}})();

I don't think there is a way to interact with a page inside of another window/frame. 我认为没有办法与另一个窗口/框架内的页面进行交互。 Your code snippet would run the function in the current window when the new window loaded. 加载新窗口后,您的代码段将在当前窗口中运行该函数。

If you are searching with google you could change the URL, something like 如果您使用Google搜索,则可以更改网址,例如

http://www.google.com/search?q=searchTerm&btnI http://www.google.com/search?q=searchTerm&btnI

This should be the same as entering the search term and clicking Im feelin lucky (which should load the first result) 这应该与输入搜索词并单击“幸运”(应加载第一个结果)相同。

I got that link from 我从那个链接

Is there a consistent way to link to Google "I Feel Lucky" result? 是否有一致的方法链接到Google“我觉得很幸运”结果?

If you are searching on your own site/ a site where you can add code maybe a query-string switch would be a good idea. 如果您在自己的站点/可以添加代码的站点上进行搜索,则可能最好使用查询字符串开关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM