从网站下载所有图像的最快最简单的方法是什么?更具体地说,http://www.cycustom.com/large/.
我正在思考wget或curl的思路.
为了澄清,首先(并且最重要的)我目前不知道如何完成这项任务.其次,我很想知道wget或curl是否有一个更容易理解的解决方案.谢谢.
---更新@sarnold ---
谢谢你的回复.我认为这也可以解决问题.但事实并非如此.这是命令的输出:
wget --mirror --no-parent http://www.cycustom.com/large/
--2012-01-10 18:19:36-- http://www.cycustom.com/large/
Resolving www.cycustom.com... 64.244.61.237
Connecting to www.cycustom.com|64.244.61.237|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `www.cycustom.com/large/index.html'
[ <=> ] 188,795 504K/s in 0.4s
Last-modified header missing -- time-stamps turned off.
2012-01-10 18:19:37 (504 KB/s) - `www.cycustom.com/large/index.html' saved [188795]
Loading robots.txt; please ignore errors.
--2012-01-10 18:19:37-- http://www.cycustom.com/robots.txt
Connecting to www.cycustom.com|64.244.61.237|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 174 [text/plain]
Saving to: `www.cycustom.com/robots.txt'
100%[======================================================================================================================================================================================================================================>] 174 --.-K/s in 0s
2012-01-10 18:19:37 (36.6 MB/s) - `www.cycustom.com/robots.txt' saved [174/174]
FINISHED --2012-01-10 18:19:37--
Downloaded: 2 files, 185K in 0.4s (505 KB/s)
Run Code Online (Sandbox Code Playgroud)
这是创建的文件的图片https://img.skitch.com/20120111-nputrm7hy83r7bct33midhdp6d.jpg
我的目标是拥有一个充满图像文件的文件夹.以下命令未实现此目标.
wget --mirror --no-parent http://www.cycustom.com/large/
Run Code Online (Sandbox Code Playgroud)
wget --mirror --no-parent http://www.example.com/large/
Run Code Online (Sandbox Code Playgroud)
这--no-parent
可以防止它吞下整个网站。
啊,我看到他们已经放置了一个robots.txt
要求机器人不要从该目录下载照片:
$ curl http://www.cycustom.com/robots.txt
User-agent: *
Disallow: /admin/
Disallow: /css/
Disallow: /flash/
Disallow: /large/
Disallow: /pdfs/
Disallow: /scripts/
Disallow: /small/
Disallow: /stats/
Disallow: /temp/
$
Run Code Online (Sandbox Code Playgroud)
wget(1)
没有记录任何可以忽略的方法robots.txt
,我从来没有找到一种简单的方法来执行--mirror
in的等效方法curl(1)
。如果你想继续使用wget(1)
,那么你就需要在中间插入一个HTTP代理的是回报404
的GET /robots.txt
请求。
我认为改变方法更容易。由于我想获得更多使用Nokogiri 的经验,因此我想出了以下方法:
wget --mirror --no-parent http://www.example.com/large/
Run Code Online (Sandbox Code Playgroud)
这只是一个快速而肮脏的脚本——两次嵌入 URL 有点难看。因此,如果这是为了长期生产使用,请先将其清理干净——或者弄清楚如何使用rsync(1)
。
robots.txt
通过添加以下选项可以忽略该文件:
-e robots=off
Run Code Online (Sandbox Code Playgroud)
我还建议添加一个选项来减慢下载速度,以限制服务器上的负载。例如,此选项在一个文件和下一个文件之间等待 30 秒:
--wait 30
Run Code Online (Sandbox Code Playgroud)