1
0

More than 1 year has passed since last update.

WEBページのリンク一覧を取得するスクリプト【備忘録】

Last updated at Posted at 2023-07-26

コンソールにリンク一覧を表示する

Javascriptを使ってWebページのリンクをコンソールに表示するためスクリプト

// 現在のページ上のすべてのリンクを表示するコンソールスクリプト
(function () {
  // ページ上のすべてのリンク要素を取得
  const links = document.querySelectorAll("a");

  // 取得したリンク要素をループしてリンクを表示
  links.forEach((link) => {
    const linkText = link.textContent;
    const linkURL = link.href;
    console.log(`${linkText} - ${linkURL}`);
  });
})();

ブラウザのデベロッパーコンソール(通常はF12キーで開きます)にこのスクリプトを貼り付けて実行すると、ページ上のすべてのリンクがコンソールに表示されます。

1
0
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0