Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get all the href attributes of a web site [duplicate]

can anybody tell me a way to get all the href attributes(links) in a web site using javascript?if you could give me a code example, i will be most thankful.

like image 753
netha Avatar asked Oct 06 '10 10:10

netha


1 Answers

You can use document.links to get the anchors, then just loop through grabbing the href, like this:

var arr = [], l = document.links; for(var i=0; i<l.length; i++) {   arr.push(l[i].href); } //arr is now an array of all the href attributes from the anchors in the page 

You can test it out here, you could filter it more before the .push() call on the array if you wanted, but that's the concept for grabbing the links and looping through.

like image 63
Nick Craver Avatar answered Sep 22 '22 00:09

Nick Craver