Skip to content

Instantly share code, notes, and snippets.

@ericharley
Created September 19, 2022 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericharley/bd653fcf8228cba43979c97d6efcf8da to your computer and use it in GitHub Desktop.
Save ericharley/bd653fcf8228cba43979c97d6efcf8da to your computer and use it in GitHub Desktop.
Quickly extract all links from a web page using the browser console
// source https://towardsdatascience.com/quickly-extract-all-links-from-a-web-page-using-javascript-and-the-browser-console-49bb6f48127b
var x = document.querySelectorAll("a");
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment