简体   繁体   English

循环浏览网站上的链接,然后点击链接javascript / jquery

[英]Loop through links on site and click links javascript/jquery

I am trying to loop through all the links on a site and autoclick some links in order to vote for here is what I have so far: 我试图遍历网站上的所有链接并自动点击一些链接,以便投票到这里是我到目前为止:

    function x(){
        for(var e in document.getElementsByTagName("a")){ 
            alert(e.getAttribute("href"))
            e.click;
        }
    }

This currently does not work I think it maybe to do with something simple like the braces/; 这当前不起作用我认为它可能与简单的像大括号/; key, I'm an absolute beginner to javascript so please bear with me. 关键,我是javascript的绝对初学者所以请耐心等待。 I assume you get the drift of what I want to do, I have completed this task in another language but still did not get the vote to register, I believe this maybe something to do with the site using jquery? 我假设你得到了我想做的事情的漂移,我用另一种语言完成了这个任务,但仍然没有得到注册的投票,我相信这可能与使用jquery的网站有关? My question is, How can I get this simple script working for a start, and 2) Is there a different click method for Jquery I can use instead of what I have up there 3) How Can I check for 6 specific URLs and click only these. 我的问题是,我怎样才能让这个简单的脚本开始工作,2)是否有一个不同的Jquery点击方法我可以使用而不是我在那里3)我如何检查6个特定的URL并单击这些。 I also need to execute this from the browser using javascript:xxx_code_here 我还需要使用javascript:xxx_code_here从浏览器执行此操作

Any ideas? 有任何想法吗?

Thank you 谢谢

use jquery like 使用jquery就好

$("a").each(function ()
{
   $(this).trigger('click');//for clicking element
   var href = $(this).attr("href");
});

You can use trigger : 你可以使用触发器

With JQuery you could use this : 使用JQuery,您可以使用:

$("a").each(function(){
    alert($(this).attr('href'));
    $(this).trigger('click');
};

You can do this with pure-javascript 你可以用pure-javascript做到这一点

function x() { // Please find a better name!
    for(var a in document.getElementsByTagName("a")) {
        alert(a.href);
        a.click(); // Careful, IE only, see comments
    }
}

With jQuery, you have shorter code: 使用jQuery,您可以使用更短的代码:

function x() {
    $("a").each(function (i, a) {
        alert(a.href);
        a.click();
    });
}
$("a").each(function ()
{
    window.location.href = $(this).attr('href');
    // $(this).trigger('click');
});
javascript: var validUrls = ["http://targetsite.com/votefraud1","http://targetsite.com/votefraud2","http://targetsite.com/votefraud3"];

function x() { 
 for(var a in document.getElementsByTagName("a")) {
   if(validUrls.indexOf(a.href) != -1){
      window.open(a.href,'');
    }
  }
}

x();

If this doesn't work we might need more info on what exactly the click event is supposed to do on whatever site you're trying to game the voting system on 如果这不起作用,我们可能需要更多信息,确定点击事件应该在您尝试游戏投票系统的任何网站上做什么。

This Worked for Me 这为我工作

Each link is opened in New Tab 每个链接都在新标签中打开

$("a").each(function ()
{
    window.open($(this).attr('href'),"_blank");
});

If At first time this time links are not opened , then you have to enable popups on the webpage . 如果第一次没有打开链接,那么您必须在网页上启用弹出窗口。

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

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