foo*_*bar 9 download wget recursive
命令
$ wget -r http://www.comp.brad.ac.uk/research/GIP/tutorials/index.html
Run Code Online (Sandbox Code Playgroud)
只下载index.html
和robots.txt
对我来说,即使其中有指向同一目录中更多页面的链接。例如
<A HREF="viewp.html">Viewpoint specification</A>
Run Code Online (Sandbox Code Playgroud)
为什么wget
不理会呢?
Liz*_*rdx 19
我对此进行了测试,并发现了问题:
wget 尊重 robots.txt 除非明确告知不要这样做。
wget -r http://www.comp.brad.ac.uk/research/GIP/tutorials/index.html
--2015-12-31 12:29:52-- http://www.comp.brad.ac.uk/research/GIP/tutorials/index.html
Resolving www.comp.brad.ac.uk (www.comp.brad.ac.uk)... 143.53.133.30
Connecting to www.comp.brad.ac.uk (www.comp.brad.ac.uk)|143.53.133.30|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 878 [text/html]
Saving to: ‘www.comp.brad.ac.uk/research/GIP/tutorials/index.html’
www.comp.brad.ac.uk/research/GI 100%[======================================================>] 878 --.-KB/s in 0s
2015-12-31 12:29:53 (31.9 MB/s) - ‘www.comp.brad.ac.uk/research/GIP/tutorials/index.html’ saved [878/878]
Loading robots.txt; please ignore errors.
--2015-12-31 12:29:53-- http://www.comp.brad.ac.uk/robots.txt
Reusing existing connection to www.comp.brad.ac.uk:80.
HTTP request sent, awaiting response... 200 OK
Length: 26 [text/plain]
Saving to: ‘www.comp.brad.ac.uk/robots.txt’
www.comp.brad.ac.uk/robots.txt 100%[======================================================>] 26 --.-KB/s in 0s
2015-12-31 12:29:53 (1.02 MB/s) - ‘www.comp.brad.ac.uk/robots.txt’ saved [26/26]
FINISHED --2015-12-31 12:29:53--
Run Code Online (Sandbox Code Playgroud)
如您所见, wget 完美地完成了您的要求。
在这种情况下,robots.txt 说什么?
cat robots.txt
User-agent: *
Disallow: /
Run Code Online (Sandbox Code Playgroud)
所以这个网站不希望机器人下载东西,至少不是那些正在阅读和关注 robots.txt 的,通常这意味着他们不想在搜索引擎中被索引。
wget -r -erobots=off http://www.comp.brad.ac.uk/research/GIP/tutorials/index.html
Run Code Online (Sandbox Code Playgroud)
现在,如果 wget 的功能太强大而您无法学习,那也没关系,但不要误以为缺陷出在 wget 中。
但是,对站点进行递归下载存在风险,因此有时最好使用限制来避免抓取整个站点:
wget -r -erobots=off -l2 -np http://www.comp.brad.ac.uk/research/GIP/tutorials/index.html
Run Code Online (Sandbox Code Playgroud)
-l2
表示最多 2 个级别。-l
意思是:水平。-np
意味着不要在树中向上移动,而是从起始页面进入。-np
意思是:没有父母。它只取决于目标页面,有时您想确切地指定要获取和不获取的内容,例如,在这种情况下,您只会获得默认的 .html/.htm 扩展名,而不是图形、pdf、音乐/视频扩展名。该-A
选项允许您添加要抓取的扩展类型。
顺便说一下,我查了一下,我的 wget 版本 1.17 是 2015 年的。不确定您使用的是什么版本。顺便说一下,Python 也是在 90 年代创建的,所以按照你的推理,python 也是 90 年代的垃圾。
我承认wget --help
它非常强大且功能丰富,wget 手册页也是如此,因此可以理解为什么有人不想阅读它,但是有大量在线教程可以告诉您如何执行最常见的 wget 操作。