Arthur Camberlein >> SEO & Data articles >> How to extract link directly from your Browser?

How to extract link directly from your Browser?

How to extract link directly from your Browser?

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:

  1. Go to any page on your browser (Google Chrome, Firefox, Opera, Brave, ...)
  2. Right click to access the 'Inspect'
  3. Go to the 'Console' tab
  4. Paste the code below
  5. Click to 'Copy' button
  6. Open a new document (txt, csv, or sheet.new)
  7. Paste the content
  8. 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.

Back to blog

Blog post taggued in:SEO, Tips

Related blog posts: