import os, requests, time # Set directory to directory where this python file is in cwd = os.getcwd() filebase = 'Survey123Connect_x64_3_11_' url = 'https://gisupdates.esri.com/Survey123/3.11/'+filebase for i in range(0,999): # Iterate through minor version numbers until we get a hit try: # query our url, if there is a hit, save to file and then exit; otherwise continue query = url+str(i)+'.exe' with requests.get(query,stream=True) as r: if r.status_code == requests.codes.ok: with open(os.path.join(cwd,filebase+str(i)+'.exe'),'wb') as f: for chunk in r.iter_content(chunk_size=32*1024): f.write(chunk) print(query) break else: print(i,r.status_code) except requests.exceptions.HTTPError as e: print(e) continue # We will be nice and not slam Esri's server time.sleep(0.5)