Last active
March 17, 2025 07:49
-
-
Save ktaranov/41f32478f701d8cdb598efbbf70e379e to your computer and use it in GitHub Desktop.
[extract_all_links_from_web_pag] Quickly extract all links from a web page using the browser console to html table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://towardsdatascience.com/quickly-extract-all-links-from-a-web-page-using-javascript-and-the-browser-console-49bb6f48127b | |
let x = document.querySelectorAll("a"); | |
let myarray = []; | |
for (let i = 0; i < x.length; i++) { | |
let nametext = x[i].textContent; | |
let cleantext = nametext.replace(/\s+/g, " ").trim(); | |
let cleanlink = x[i].href; | |
myarray.push([cleantext, cleanlink]); | |
} | |
function make_table() { | |
let links_table = "<table><thead><th>Name</th><th>Links</th></thead><tbody>"; | |
for (let i = 0; i < myarray.length; i++) { | |
links_table += "<tr><td>" + myarray[i][0] + "</td><td>" + myarray[i][1] + "</td></tr>"; | |
} | |
let w = window.open(""); | |
w.document.write(links_table); | |
} | |
make_table(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment