【问题标题】:Download images from html and keep the folder structure从 html 下载图片并保持文件夹结构
【发布时间】:2015-03-09 14:09:26
【问题描述】:

我需要下载超过 100.000 张图片。图片有:.png、.jpg、.jpeg、.gif 格式。 我有权使用这些图片。他们为我提供了一个包含所有 url 的 XML 文件

网址有结构

其他域/productimages/code/imagename.jpg/.png/.gif

我有一个名为$codes[]的php数组中的所有代码 我还有数组$images[]上所有图像的完整路径@

我需要下载所有这些图片并保持相同的结构

mydomain/productimages/code/imagename.jpg/.png/.gif

到目前为止,我通过互联网进行的研究是:

遍历所有页面(每个酒店代码)

   $i = 1;
   $r = 100000;

while ($i < $r) {
    $html = get_data('http://otherdomain.com/productimages/'.$codes[$i].'/');
    getImages($html);
    $codes[$i++];
}

    function getImages($html) {
        $matches = array();
        $regex = '~http://otherdomain.com/productimages/(.*?)\.jpg~i';
        preg_match_all($regex, $html, $matches);
        foreach ($matches[1] as $img) {
            saveImg($img);
        }
    }

    function saveImg($name) {
        $url = 'http://otherdomain.com/productimages/'.$name.'.jpg';
        $data = get_data($url);
        file_put_contents('photos/'.$name.'.jpg', $data);
    }

你能帮我解决这个问题吗,因为脚本根本不起作用

【问题讨论】:

  • 尝试使用 file_get_contents 而不是 get_data
  • 仍然没有效果@flyingeagle413

标签: php regex image


【解决方案1】:

我可能会建议您使用更简单、更快捷的方法来完成这项任务。 将完整的 URL 写入 list.txt 执行 wget -x -i list.txt 命令,将下载所有图片并根据站点结构放置在适当的目录中。

【讨论】:

  • 它工作得很好,它是否知道我是否可以设置 wget 将所有文件下载到某个位置,例如 HTTP 根文件夹?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-26
相关资源
最近更新 更多