How to count and display all links in any web page?

If you are a developer, just a developer in any language, and sometimes, you may require to count and see all links in a web page.

You can do that in a tricky way with developer console of any browser.

const links = document.querySelectorAll('a');
console.log(`Total links: ${links.length}`);
links.forEach((link, index) => {
  console.log(`${index + 1}: ${link.href}`);
});Code language: JavaScript (javascript)

Just run inside “console” tab of browser with the link open. it will display the total number of links and display the urls too.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *