[Shell] Crawler として Wget を利用する場合のオプションを確認する
macOS では brew install できる。
[markdown]
> Wget はただのダウンローダーではなく、再帰ダウンロードやリンク変換ができる立派な「クローラー」です。
>
> [Rubyによるクローラー開発技法 巡回・解析機能の実装と21の運用例 | るびきち | コンピュータ・IT | Kindleストア | Amazon](http://www.amazon.co.jp/exec/obidos/ASIN/B00TO6KMEK/driftwood-22/ref=nosim/)
“`prettyprinted
% wget –version
GNU Wget 1.19.2 built on darwin16.7.0.
“`
> * [Wget – GNU Project – Free Software Foundation](https://www.gnu.org/software/wget/)
## Wget option
多数のオプションがあるので、必要なモノをうまく組み合わせることになる。
> * [GNU Wget 1.18 Manual](https://www.gnu.org/software/wget/manual/wget.html#Invoking)
“`prettyprinted
% wget -c –reject pdf -q -r -l0 -w2 –random-wait -p -k –no-check-certificate –exclude-directories=/tex/texs https://www.d-wood.com/tex/
“`
### Logging and Input File Options
`-q` `–quiet` 実行結果の出力を抑える。
### Download Options
`-c` `–continue` 部分的にダウンロードされたファイルの取得を続ける。
`-w seconds` 待ち時間を秒指定する。
`–random-wait` 前述の待ち時間を 0.5 から 1.5 倍の範囲でランダム化する。
### HTTPS (SSL/TLS) Options
`–no-check-certificate` 証明書のチェックをしない。
### Recursive Retrieval Options
`-r` `–recursive` 再帰ダウンロードを行う。
`-l0` `–level=depth` ダウンロードする階層の深さを指定。`0` で無限。
`-p` `–page-requisites` HTML表示に必要な画像やCSSファイルもダウンロードする。
`-k` `–convert-links` ローカルで表示できるようリンクを変換する。
### Recursive Accept/Reject Options
`-R list` `–reject list` 除外するファイルタイプを指定する。`,` で複数指定。
`-X list` `–exclude-directories=list` 除外するパスをルートから指定する。`,` で複数指定。
## Startup File
Startup File を利用することで、初期設定をまとめられる。
標準では `/etc/wgetrc`, `$HOME/.wgetrc` がロードされるが、`–config=FILE` で指定も可能。
“`prettyprinted
% wget –config=./wgetrc_local https://www.d-wood.com/tex/
“`
> * [GNU Wget 1.18 Manual](https://www.gnu.org/software/wget/manual/wget.html#Startup-File)
前述の設定をまとめると、以下のようになる。
“`prettyprinted:./wgetrc_local
# Logging and Input File Options
quiet = on
# Download Options
continue = on
random_wait = on
wait = 2
# HTTPS (SSL/TLS) Options
check_certificate = off
# Recursive Retrieval Options
recursive = on
reclevel = 0
page_requisites = on
convert_links = on
# Recursive Accept/Reject Options
reject = pdf
exclude_directories = /tex/texs
“`
売り上げランキング: 79,720
## 補遺
> * [[Ruby] gems: Webクローラ anemone を使ってみる | deadwood](https://www.d-wood.com/blog/2014/01/24_5332.html)
[/markdown]