Always wanted to quickly extract links on 1 page, from your browser, without using too many tools? This is a quick tip that I "labelled" as SEO because I use it on a regular basis to verify and get the anchor text
How to achieve that?
The whole process is the following:
- Go to any page on your browser (Google Chrome, Firefox, Opera, Brave, ...)
- Right click to access the 'Inspect'
- Go to the 'Console' tab
- Paste the code below
- Click to 'Copy' button
- Open a new document (txt, csv, or sheet.new)
- Paste the content
- Voilà
Tee code to add in the 'Console' tab to extract links in bulk
This is the JS script you could use
const results = [ ['Url', 'Anchor Text', 'External'] ]; var urls = document.getElementsByTagName('a'); for (urlIndex in urls) { const url = urls[urlIndex] const externalLink = url.host !== window.location.host if(url.href && url.href.indexOf('://')!==-1) results.push([url.href, url.text, externalLink]) // url.rel } const csvContent = results.map((line)=>{ return line.map((cell)=>{ if(typeof(cell)==='boolean') return cell ? 'TRUE': 'FALSE' if(!cell) return '' let value = cell.replace(/[\f\n\v]*\n\s*/g, "\n").replace(/[\t\f ]+/g, ' '); value = value.replace(/\t/g, ' ').trim(); return `"${value}"` }).join('\t') }).join("\n"); console.log(csvContent)
What does the code do? It scans the page for any link (URLs) and then extract the anchor text. I also added a piece of info that will help the script test if the domain of the link is the same that the page you are currently browsing.
Lastly, I added a 'button' to copy it into a CSV content.