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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:05:13  来源:igfitidea点击:

Download all images from a single directory of a website

phpjavascriptlinuxperlimage

提问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

Have a look at HTTracksoftware. It can download whole sites. Give website address site.com/images/and it will download everything in this directory. (if the directory access is not restricted by owner)

看看HTTrack软件。它可以下载整个站点。给出网站地址site.com/images/,它将下载此目录中的所有内容。(如果目录访问不受所有者限制)

回答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

Depends if the images directory allows listing the contents. 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

回答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 文件夹,然后您可以看到页面中列出的所有图像。