Last active
October 11, 2025 15:42
-
-
Save ktaranov/41f32478f701d8cdb598efbbf70e379e to your computer and use it in GitHub Desktop.
Revisions
-
ktaranov revised this gist
Feb 17, 2021 . 1 changed file with 13 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,18 @@ // 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(); -
ktaranov created this gist
Feb 17, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ # 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 table = '<table><thead><th>Name</th><th>Links</th></thead><tbody>'; for (let i=0; i<myarray.length; i++) { table += '<tr><td>'+ myarray[i][0] + '</td><td>'+myarray[i][1]+'</td></tr>'; }; let w = window.open(""); w.document.write(table); } make_table();