Last active
June 5, 2022 07:35
-
-
Save bradwindy/002c09800707539a504582d2efa6afc6 to your computer and use it in GitHub Desktop.
Script for downloading files from URL in an XML file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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