admin管理员组

文章数量:1419183

this website wants me to click ALL the links on the page (there's about 2000).

This is the code for each link:

<a href="#" id="27426879" class="unfollow">UNFOLLOW</a>

the ID changes all the time depending on the link.

Is it possible to supply me the javascript code to write into the console of google chrome to click ALL the "a" tags with the class of "unfollow" at once? thanks :)

this website wants me to click ALL the links on the page (there's about 2000).

This is the code for each link:

<a href="#" id="27426879" class="unfollow">UNFOLLOW</a>

the ID changes all the time depending on the link.

Is it possible to supply me the javascript code to write into the console of google chrome to click ALL the "a" tags with the class of "unfollow" at once? thanks :)

Share Improve this question edited Jan 13, 2013 at 20:55 Pointy 414k62 gold badges595 silver badges629 bronze badges asked Jan 13, 2013 at 20:54 Rahul KhoslaRahul Khosla 44910 silver badges21 bronze badges 1
  • 3 Inject jQuery then $('a.unfollow[href="#"]').click(); – Musa Commented Jan 13, 2013 at 20:58
Add a ment  | 

3 Answers 3

Reset to default 4

How about?

var links = document.querySelectorAll("a.unfollow[href=#]");
for (var i = 0; i < links.length; ++i) {
    links[i].click();
}

Sure is:

[].forEach.call(document.querySelectorAll('a.unfollow'), function (link){
    link.click();
});

Demo

You could do it using a plain for loop as well, but I just found it faster to do it this way.

Thanks I used chat room this code works easy: $('a.unfollow').click()

本文标签: cssJavascript Help For Chrome Console Clicking All links websiteStack Overflow