### Author: Robyn S. Gwee ### Date : Wed Oct 9, 2019 ### Remarks: Scraping layer names from config xml ############################################################################## import requests import xml.etree.ElementTree as ET NHI = "https://data.nhi.nu/site/config/application.config.xml" def getLayerList(url_root, filename): r = requests.get(url_root) root = ET.fromstring(r.text) GetCapa = [i.text for i in root.iter('url') if 'GetCapabilities' in i.text] with open(filename, 'w', encoding='utf-8') as file: for capas in GetCapa: get_list = requests.get(capas).text read_getList = ET.fromstring(get_list) for i in read_getList.iter('{http://www.opengis.net/wms}Title'): if i.text is None: pass else: file.write(i.text + '\n') file.close() getLayerList(NHI, 'NHI_LayerList.txt')