I'm trying to set up a for loop to pull in elected representatives' data for about 600,000 postal codes. The base URL stays the same, and the only part that changes is the postal code.
I'd ideally like to create a list of all the postal codes, and then use requests.get to pull in data for all the postal codes in my list. I came up with this code below, but it's only pulling in data for the last postal code in my list. I'm not really sure why this is happening and am a python beginner - so any help would be appreciated!
#loop test
postcodes = ['P0L1B0','P5A3P1', 'P5A3P2', 'P5A3P3']
for i in range(len(postcodes)):
rr = requests.get('https://represent.opennorth.ca/postcodes/{}'.format(postcodes[i]))
data1=json.loads(rr.text)
data1