top of page

use code to generate list of links on a web page

The below code, posted here by Phil Gorman can be used to easily generate a list of all of the links on a single web page.


Simply follow these steps.


1. In Chrome, right click on the web page containing the links and select 'Inspect'.


2. In the panel that opens click on the 'Console' tab.


3. In the pane at the bottom right enter the code, and then press 'ENTER'.




4. A new tab will open in the browser with a list of the links and the name of each link, or the text which contains the link. This text can then be pasted in two columns in Excel.




var x = document.querySelectorAll("a");3.

var myarray = []

for (var i=0; i<x.length; i++){

var nametext = x[i].textContent;

var cleantext = nametext.replace(/\s+/g, ' ').trim();

var cleanlink = x[i].href;

myarray.push([cleantext,cleanlink]);

};

function make_table() {

var table = '<table><thead><th>Name</th><th>Links</th></thead><tbody>';

for (var i=0; i<myarray.length; i++) {

table += '<tr><td>'+ myarray[i][0] + '</td><td>'+myarray[i][1]+'</td></tr>';

};


var w = window.open("");

w.document.write(table);

}

make_table()

Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page