简体   繁体   English

从网站的单个目录下载所有图像

[英]Download all images from a single directory of a website

I need to get all of the images from one website that are contained all in one folder. 我需要从一个网站获取所有图像,这些图像都包含在一个文件夹中。 Like for instance, (site.com/images/.*). 例如,(site.com/images/.*)。 Is this possible? 这可能吗? If so, whats the best way? 如果是这样,最好的方法是什么?

Have a look at HTTrack software. 看看HTTrack软件吧。 It can download whole sites. 它可以下载整个网站。 Give website address site.com/images/ and it will download everything in this directory. 提供网站地址site.com/images/ ,它将下载此目录中的所有内容。 (if the directory access is not restricted by owner) (如果目录访问不受所有者限制)

Do you have FTP access? 你有FTP访问权限吗?

Do you have shell access? 你有shell访问权限吗?

With Linux it's pretty easy. 使用Linux它非常简单。 Not sure about windows. 关于窗户不确定。

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. 编辑2:我刚看到PHP标签,为了创建一个可以一次性下载所有图像的PHP脚本,您必须创建一个zip(或等效的)存档并使用正确的标头发送。 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: 这里是如何在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;
        }
    }
}

如果网站允许索引,你需要做的就是wget -r --no-parent http://site.com/images/

Depends if the images directory allows listing the contents. 如果images目录允许列出内容,则取决于。 If it does, great, otherwise you would need to spider a website in order to find all the image reference to that directory. 如果确实如此,那么你需要蜘蛛网站才能找到该目录的所有图像引用。

In either case, take a look at wget . 无论哪种情况,请看看wget

如果您想查看网页正在使用的图像:如果您使用的是Chrome,则可以按F-12(或在菜单中找到“开发人员工具”),在“资源”选项卡上,左侧有一棵树,然后在“框架”下,您将看到“图像”文件夹,然后您可以看到该页面中列出的所有图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM