muffet のインストール
muffet
はウェブサイトのリンク切れをチェックしてくれるコマンドラインツールです。
Go 言語で実装されており、いろいろな OS (Linux、macOS、Windows) で利用することができます。
インストール方法は、上記サイトに記述されていますが、例えば macOS であれば、homebrew を使って次のように簡単にインストールできます。
% brew install muffet
各 OS 用の実行バイナリが欲しければ、Release ページ からダウンロードできます。
muffet の使い方
基本的な使い方は、次のように調べたいウェブページのアドレスを入力するだけです。
% muffet http://localhost:51000
リンク元のサイトアドレスと、アクセスできなかったサイトアドレスの組み合わせが一覧表示されます。
http://localhost:51000/p/eu7djpv/
404 http://localhost:51000/assets/favicon/180x180.png
404 http://localhost:51000/assets/favicon/192x192.png
http://localhost:51000/p/ckahx6k/
404 http://localhost:51000/assets/favicon/180x180.png
404 http://localhost:51000/assets/favicon/192x192.png
404 http://video.google.com/videoplay?docid=973149761529535925
404 (following redirect https://www.example.com/p/44327.html)
http://www.example.com/44327/2005/04/tipsinbox.html
muffet は複数スレッドで高速にリンクチェックを行いますが、ひとつのドメインに対する同時接続数を制限したいときは、--max-connections-per-host
オプションを指定します。
Web サーバーへの負荷を考慮したいときに使えます。
% muffet --max-connections-per-host=5 http://localhost:51000
--exclude
オプションを使うと、チェック対象外とするアドレスを正規表現で指定できます。
例えば、次のようにすれば、https://
で始まるリンクをチェック対象外にできます。
ローカル Web サーバーで開発している場合、このオプション指定によって外部サイトのリンクだけをチェック対象外にできます。
% muffet --exclude="https://.*" http://localhost:51000
その他のオプションは、muffet --help
で確認できます。
% muffet --help
Usage:
muffet [options] <url>
Application Options:
-b, --buffer-size=<size> HTTP response buffer size in bytes (default: 4096)
-c, --max-connections=<count> Maximum number of HTTP connections (default: 512)
--max-connections-per-host=<count> Maximum number of HTTP connections per host (default: 512)
-e, --exclude=<pattern>... Exclude URLs matched with given regular expressions
--follow-robots-txt Follow robots.txt when scraping pages
--follow-sitemap-xml Scrape only pages listed in sitemap.xml
--header=<header>... Custom headers
-f, --ignore-fragments Ignore URL fragments
--json Output results in JSON
-r, --max-redirections=<count> Maximum number of redirections (default: 64)
--rate-limit=<rate> Max requests per second
-t, --timeout=<seconds> Timeout for HTTP requests in seconds (default: 10)
-v, --verbose Show successful results too
--proxy=<host> HTTP proxy host
--skip-tls-verification Skip TLS certificate verification
--one-page-only Only check links found in the given URL
--color=[auto|always|never] Color output (default: auto)
-h, --help Show this help
--version Show version
現状そこまで凝ったことはできないようですね。 オプションの使い方もよくわからない点が多いので、公式サイトのドキュメントが拡充されることを期待します。