【发布时间】:2018-05-10 15:37:54
【问题描述】:
我想使用以下 bash 脚本从奥地利国家图书馆的 this 网站(wget)下载一些免费下载的 pdf(旧报纸的副本):
#!/bin/bash
#A script to download issues of the Leipziger Zeitung (1814-1857)
for year in {14..57}; do
DATES=$(curl -sS "http://anno.onb.ac.at/cgi-content/anno?aid=lzg&datum=18$year" | gawk 'match($0, /datum=([^&]+)/, ary) {print ary[1]}' | xargs echo)
for date in $DATES; do
echo "Downloading for $date"
curl "http://anno.onb.ac.at/cgi-content/anno_pdf.pl?aid=lzg&datum=$date" -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'DNT: 1' -H "Referer: http://anno.onb.ac.at/cgi-content/anno?aid=lzg&datum=$date" -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.9' --compressed
wget -A pdf -nc -E -nd --no-check-certificate --content-disposition http://anno.onb.ac.at/pdfs/ONB_lzg_$date.pdf
done
done
我发现该脚本仅从星期一和星期六下载问题(如果不可用,则分别从星期二开始下载问题,如果可用,则分别下载星期日问题),而不是在一周中的其余时间,请参阅下面的 bash 输出。
Downloading for 18140228
Downloading for 18140402
Downloading for 18140404
Downloading for 18140409
Downloading for 18140412
Downloading for 18140416
Downloading for 18140418
Downloading for 18140423
Downloading for 18140425
Downloading for 18140430
在过去,并非每天或每月都会发布或今天可用。但是,如果您比较 1814 年的 this 日历,例如四月,您会发现该脚本每周只下载两期。它下载 1814 年 4 月 4 日和 4 月 9 日的期刊,但不下载 4 月 5 日至 4 月 7 日的可用期刊。对于 1814 年 4 月的其他周以及 1814 年至 4 月 9 日相关时间范围内的任何其他可用月份都是如此1857.
我是编写脚本的新手,对当前的脚本有帮助(请参阅此处的this 问题),所以我不知道如何下载所有可用的问题。
另外,我用time 测量到 curl 命令需要 3 到 5 秒才能执行。有没有办法加速脚本?
【问题讨论】: