ワンライナーで愛媛県のコロナ検査結果のPDFをダウンロード

qiita.com

curl -sS https://www.pref.ehime.jp/h25500/kansen/covid19.html | sed 's/ //g' | xmllint --html --xpath '//div/ul/li/a[starts-with(@href, "/h25500/kansen/documents/press04") and contains(@href, ".pdf")]/@href' - | xargs -n 1 | cut -d= -f2 | sed 's;^;https://www.pref.ehime.jp;;' | xargs -n 1 curl -L#O
curl -sS https://www.pref.ehime.jp/h25500/kansen/covid19.html \
| sed 's/ //g' \
| xmllint --html --xpath '//div/ul/li/a[starts-with(@href, "/h25500/kansen/documents/press04") and contains(@href, ".pdf")]/@href' - \
| xargs -n 1 \
| cut -d= -f2 \
| sed 's;^/;https://www.pref.ehime.jp/;;' \
| xargs -n 1 curl -L#O
sed
" "を削除

xmllint
xpathでpdf抽出

xargs
「-n 1」で1行ずつ処理

cut
「-d=」で「-d」分割、「=」区切り文字
「-f2」で2番目抽出

sed
相対アドレスの場合絶対アドレス「https://www.pref.ehime.jp/」を補完

xargs
curlでダウンロード