Linux 从网站的单个目录下载所有图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4622006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Download all images from a single directory of a website
提问by bryan sammon
I need to get all of the images from one website that are contained all in one folder. Like for instance, (site.com/images/.*). Is this possible? If so, whats the best way?
我需要从一个网站获取所有包含在一个文件夹中的图像。例如,(site.com/images/.*)。这可能吗?如果是这样,最好的方法是什么?
采纳答案by Tasawer Khan
回答by Reese Moore
if the site allows indexing, all you need to do is wget -r --no-parent http://site.com/images/
如果站点允许索引,您需要做的就是 wget -r --no-parent http://site.com/images/
回答by Orbling
回答by rich97
Do you have FTP access?
你有 FTP 访问权限吗?
Do you have shell access?
你有shell访问权限吗?
With Linux it's pretty easy. Not sure about windows.
有了Linux,这很容易。不确定窗户。
wget -H -r --level=1 -k -p http://example.com/path/to/images
Edit: Just found wget for windows.
编辑:刚刚找到wget for windows。
Edit 2: I just saw the PHP tag, in order to create a PHP script which downloads all images in one go, you will have to create a zip (or equivalent) archive and send that with the correct headers. Here is how to zip a folder in php, it wouldn't be hard to extract only the images in that folder, just edit the code given to say something like:
编辑 2:我刚刚看到了 PHP 标签,为了创建一个一次性下载所有图像的 PHP 脚本,您必须创建一个 zip(或等效的)存档并使用正确的标题发送它。这是在 php 中压缩文件夹的方法,仅提取该文件夹中的图像并不难,只需编辑给出的代码即可:
foreach ($iterator as $key=>$value) {
if (!is_dir($key)) {
$file = basename($key);
list($name, $ext) = explode('.', $key);
switch ($ext) {
case "png":
case "gif":
case "jpg":
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
break;
}
}
}
回答by live-love
If you want to see the images a web page is using: if you are using Chrome, you can just press F-12 (or find Developer Tools in the menu) and on the Resources tab, there's a tree on the left, and then under Frames, you will see the Images folder, then you can see all the images the page uses listed in there.
如果您想查看网页正在使用的图像:如果您使用的是 Chrome,您只需按 F-12(或在菜单中找到开发人员工具),在资源选项卡上,左侧有一棵树,然后在 Frames 下,您将看到 Images 文件夹,然后您可以看到页面中列出的所有图像。