Here is a script that will walk through the directory of folders, services, and layers. Ultimately, it prints the folder name, the service name, the layer name, and layer type for all available layers.
See this answer for clarification on how the URLs were derived.
import urllib.request, json
root_url = r'https://ext-geodata-nationella.lansstyrelsen.se/arcgis/rest/services/?f=pjson'
download the root json
with urllib.request.urlopen(root_url) as url:
data = json.loads(url.read().decode())
iterate through the 'folders' key of the root json
for folder in data['folders']:
# construct a url to get the json of the folder
folder_url = root_url.split('?')[0] + folder + '?f=pjson'
# download the folder json
with urllib.request.urlopen(folder_url) as url:
sub_data = json.loads(url.read().decode())
# some urls require a log in, in which case the json has a key called 'error'
if 'error' not in sub_data.keys():
for service in sub_data['services']:
# construct the url for the service json
service_url = folder_url.split(folder)[0] + service['name'] + '/MapServer/?f=pjson'
# download service json
with urllib.request.urlopen(service_url) as url:
sub_sub_data = json.loads(url.read().decode())
# iterate through service json 'layers' key
for layer in sub_sub_data['layers']:
# do something with results
print(folder, '|', service['name'], '|', layer['name'], '|', layer['type'])
Sample of output (the whole output is very large).
BS | BS/lst_bs_mov03 | BS Förbudsområde 1-årsregeln | Feature Layer
BS | BS/lst_bs_mov03 | BS Beviljade bearbetningskoncessioner | Feature Layer
Energimyndigheten | Energimyndigheten/lst_energigas_fak09 | Fordonsgasinfrastruktur (grupp) | Group Layer
Energimyndigheten | Energimyndigheten/lst_energigas_fak09 | Tankställen för flytande fordonsgas | Feature Layer
Energimyndigheten | Energimyndigheten/lst_energigas_fak09 | Tankställen för fordonsgas | Feature Layer
FHM | FHM/lst_fhm_fak02 | FHM Badplatser (alla) | Feature Layer
FM | FM/lst_fm_riksintressen_3_9 | FM_Riksintresse_pa_land_MB3kap9 | Feature Layer
FM | FM/lst_fm_riksintressen_3_9 | FM_Riksintresse_i_havet_sjoovningsomrade_MB3kap9 | Feature Layer