I'm trying to set up a for loop to pull in elected representatives' data for about 600,000 postal codes. 基本 URL 保持不變,唯一改變的部分是郵政編碼。理想情況下,我想創(chuàng)建所有郵政編碼的列表,然后使用 requests.get 提取列表中所有郵政編碼的數(shù)據(jù)。我在下面想出了這個代碼,但它只是為我的列表中的最后一個郵政編碼提取數(shù)據(jù)。我不確定為什么會發(fā)生這種情況,我是一名 Python 初學(xué)者 - 所以任何幫助將不勝感激!#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
添加回答
舉報
0/150
提交
取消