Skip to content

Instantly share code, notes, and snippets.

@bradwindy
Last active June 5, 2022 07:35
Show Gist options
  • Save bradwindy/002c09800707539a504582d2efa6afc6 to your computer and use it in GitHub Desktop.
Save bradwindy/002c09800707539a504582d2efa6afc6 to your computer and use it in GitHub Desktop.
Script for downloading files from URL in an XML file
import os
import xml.etree.ElementTree as ET
from urllib.parse import urlparse
import wget
path = './pads'
for file in os.listdir(path):
current = os.path.join(path, file)
if os.path.isfile(current):
tree = ET.parse(current)
root = tree.getroot()
for info in root.findall('Web_Info'):
for dlurls in info.findall('Download_URLs'):
for url in dlurls.iter('Primary_Download_URL'):
filename = os.path.basename(urlparse(url.text).path)
print("DOWNLOADING: " + filename)
try:
wget.download(url.text,'./dl/' + filename)
except Exception as ex:
print('Unable to download: ' + filename + ' due to error: ' + str(ex))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment