
URLとJavaScriptファイルの位置を収集するための高速なGo言語製ウェブクローラーです。基本的には、素晴らしいGocollyライブラリのシンプルな実装です。
単一URL:
echo https://google.com | hakrawler
複数URL:
cat urls.txt | hakrawler
標準入力の各行に対して5秒のタイムアウト:
cat urls.txt | hakrawler -timeout 5
すべてのリクエストをプロキシ経由で送信:
cat urls.txt | hakrawler -proxy http://localhost:8080
サブドメインを含める:
echo https://google.com | hakrawler -subs
注意: よくある問題として、ツールがURLを返さないことがあります。これは通常、ドメイン(例: https://example.com)を指定したものの、サブドメイン(例: https://www.example.com)にリダイレクトされる場合に発生します。サブドメインがスコープに含まれていないため、URLが表示されません。これを解決するには、リダイレクトチェーン内の最終URLを指定するか、`-subs` オプションを使用してサブドメインを含めてください。
Googleのすべてのサブドメインを取得し、http(s)に応答するものを見つけて、すべてクロールします。
echo google.com | haktrails subdomains | httpx | hakrawler
まず、Goをインストールする必要があります。
次に、以下のコマンドを実行してhakrawlerをダウンロード&コンパイルします:
go install github.com/hakluke/hakrawler@latest
これで ~/go/bin/hakrawler を実行できます。フルパスなしで hakrawler だけを実行したい場合は、export PATH="~/go/bin/:$PATH" を設定する必要があります。この設定を永続化したい場合は、~/.bashrc ファイルにこの行を追加することもできます。
echo https://www.google.com | docker run --rm -i hakluke/hakrawler:v2 -subs
上記のdockerhubの方法を使う方がはるかに簡単ですが、ローカルで実行したい場合は以下の手順に従ってください。
git clone https://github.com/hakluke/hakrawler
cd hakrawler
sudo docker build -t hakluke/hakrawler .
sudo docker run --rm -i hakluke/hakrawler --help
注意: これにより、すべての機能を備えていない古いバージョンのhakrawlerがインストールされ、バグが発生する可能性があります。他の方法のいずれかを使用することをお勧めします。
sudo apt install hakrawler
その後、hakrawlerを実行するには:
echo https://www.google.com | docker run --rm -i hakluke/hakrawler -subs
Usage of hakrawler:
-d int
Depth to crawl. (default 2)
-dr
Disable following HTTP redirects.
-h string
Custom headers separated by two semi-colons. E.g. -h "Cookie: foo=bar;;Referer: http://example.com/"
-i Only crawl inside path
-insecure
Disable TLS verification.
-json
Output as JSON.
-proxy string
Proxy URL. E.g. -proxy http://127.0.0.1:8080
-s Show the source of URL based on where it was found. E.g. href, form, script, etc.
-size int
Page size limit, in KB. (default -1)
-subs
Include subdomains for crawling.
-t int
Number of threads to utilise. (default 8)
-timeout int
Maximum time to crawl each URL from stdin, in seconds. (default -1)
-u Show only unique urls.
-w Show at which link the URL is found.