0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Githubの検索画面でリポジトリURLを一括で抽出するjsスクリプト

Posted at

スクリーンショット 2026-01-25 11.16.08.png
このような画面で使えるjsスクリプトです。

経緯

Githubで、特定の検索条件した結果を、一括でURLで保存したいと言う状況があったので、
後述するスクリプトを作成しました。

コード

①定義

var grobalText = "";

function extractRepositoryURLs() {
  var text = "";
  const links = [...document.querySelectorAll('a')]
    .map(a => a.href)
    .filter(url => {
      const m = url.match(
        /^https:\/\/github\.com\/(?!.*(?:topic|sponsors|stargazers|search|contact))[^\/]+\/[^\/]+$/
      );
      return m !== null;
    });


  const uniqueLinks = [...new Set(links)];

  uniqueLinks.forEach(url => {
    text += url + "\n";
  });

  grobalText += text + "\n";
  clickNextPage();
}

function clickNextPage() {
  const xpath = '/html/body/div[1]/div[6]/main/react-app/div/div/div[1]/div/div/div[2]/div/div/div[1]/div[5]/div/nav/div/a[10]';
  const result = document.evaluate(
    xpath,
    document,
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null
  );
  const el = result.singleNodeValue;
  if (el) {
    el.click();
  } else {
    console.error("Next link not found");
  }
}

function logRepositoryURLs() {
  console.log(grobalText);
}

②呼び出し

extractRepositoryURLs();
clickNextPage();
extractRepositoryURLs();
logRepositoryURLs();

使い方

①. Githubの検索結果一覧を開く
②. Chrome devtoolのConsoleで定義のjsを貼り付け、実行
③. ②実行時に次のページ(ページネーションの次)を開くので、そこでextractRepositoryURLsを実行
④. ②~③を繰り返す
⑤. もういいやと思ったら、logRepositoryURLs()でURLテキストをログ出力してコピー

Tips

URLを一括で開く、pastyなどと組み合わせると便利です。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?