简体   繁体   English

如何从XML文件下载图像?

[英]How do I download images from an XML file?

I'm rebuilding a website for fun (but also making it better) and I want to batch download the images that are on the site. 我正在重建一个网站以便娱乐(但同时也会使其变得更好),并且我想批量下载该网站上的图像。 I have found an XML file which contains all the links to the images (or at least some of them). 我找到了一个XML文件,其中包含指向图像的所有链接(或至少其中一些链接)。 Here's the file. 这是文件。

Is there a way to download all the images in this XML with a Windows program or a script of some sort? 是否可以使用Windows程序或某种脚本来下载此XML中的所有图像? Thank you very much. 非常感谢你。

You need to do three things: 您需要做三件事:

  1. Extract/create the urls from the xml file 从xml文件中提取/创建网址
    • Use a text editor's find & replace (sublime texts ctrl-shift-g is especially great) 使用文本编辑器的查找和替换(崇高文本ctrl-shift-g尤其出色)
  2. Use an http client to download one url 使用http客户端下载一个网址
  3. Expand this method to loop over all the urls: 扩展此方法以遍历所有URL:
    • Trivial if you used DownloadThemAll, see this stack overflow if you use a batch file, or consider using powerhsell. 如果您使用DownloadThemAll,则很简单;如果使用批处理文件,则请参阅此堆栈溢出 ;或者考虑使用powerhsell。

Additionally, you could install other programming languages such as python or ruby, and use an http library that they have. 此外,您可以安装其他编程语言(例如python或ruby),并使用它们拥有的http库。 The setup is longer, but the syntax is likely easier once setup in such languages. 设置时间更长,但是一旦以这种语言设置,语法可能会更容易。

Update: If you use search and replace on the xml document to create an html page containing a list of links like so: 更新:如果您在xml文档上使用搜索和替换来创建一个包含链接列表的html页面,如下所示:

<body>  
  <a href="http://gkvrozenburg-voorne.nl/images/45.jpg" download>link</a>
  <a href="http://gkvrozenburg-voorne.nl/images/IMG_3026.jpg" download>link</a>
  <a href="http://gkvrozenburg-voorne.nl/images/IMG_3037.jpg" download>link</a>
  <a href="http://gkvrozenburg-voorne.nl/images/IMG_3039.jpg" download>link</a>
  <a href="http://gkvrozenburg-voorne.nl/images/IMG_3047.jpg" download>link</a>
</body>

Then you can open it up in a browser, start the browsers javascript console and type the following: 然后,您可以在浏览器中将其打开,启动浏览器的JavaScript控制台并输入以下内容:

var anchors = document.getElementsByTagName('a')
for (var i = 0; i < anchors.length; i++) {
  anchors[i].click()
}

This will download all of the images. 这将下载所有图像。

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

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