I am struggling to get this while loop to work in python.
urlList = [] while True: for r in range(1, 5000): try: response = urllib.request.urlopen('www.somewebsite.com/v0/info/' + str(r) + '.json') html = response.read().decode('utf-8') data = json.loads(html) if 'url' in data: urlList.append(data['url']) if len(urlList) == 100: break except urllib.error.HTTPError as err: print (err) continue print (urlList) I currently have the if statement to break out of the while loop if the list length equals 100. which throws an odd error of urllib.error.URLError:
I also tried While len(urlList) != 100 which makes the process not run. Also While len(urlList) < 100 just makes it run through the entire range function.
'www.somewebsite.com' + str(r) + '.json'a real url?www.somewebsite.com' + str(r) + '.jsonwill give you a malformed URL, you need a/between the domain and the file, no?