jeroen-meijer
jeroen-meijer

Reputation: 2974

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). 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? Thank you very much.

Upvotes: 0

Views: 7787

Answers (1)

Dan
Dan

Reputation: 3020

You need to do three things:

  1. Extract/create the urls from the xml file
    • Use a text editor's find & replace (sublime texts ctrl-shift-g is especially great)
  2. Use an http client to download one url
  3. Expand this method to loop over all the urls:
    • Trivial if you used DownloadThemAll, see this stack overflow if you use a batch file, or consider using powerhsell.

Additionally, you could install other programming languages such as python or ruby, and use an http library that they have. 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:

<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:

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

This will download all of the images.

Upvotes: 1

Related Questions