我在一個 CSV 文件的一列中有大約 20,000 個郵政編碼。我正在嘗試通過 API 根據這些郵政編碼提取一些地理選舉數據。此 API 的 url 迭代到最后(每次迭代的郵政編碼都會更改)。我嘗試了許多不同的代碼示例,但都沒有奏效。編輯:在下面粘貼一個我現在知道不起作用的示例 - 主要是因為我不需要條帶功能。但是,如何讓循環直接從 CSV 文件中提取郵政編碼?還粘貼我收到的錯誤消息。 responses = list() with open("testpostal.csv") as f: for postal in map(str.strip,f): rrr = requests.get('https://represent.opennorth.ca/postcodes/{}'.format(postal)) data = json.loads(rrr.text) responses.append(data) print(responses)JSONDecodeError Traceback (most recent call last)<ipython-input-182-05e370407e9c> in <module>() 9 for postal in map(str.strip,f): 10 rrr = requests.get('https://represent.opennorth.ca/postcodes/{}'.format(postal))---> 11 data = json.loads(rrr.text) 12 responses.append(data) 13 ~/anaconda3/lib/python3.7/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 346 parse_int is None and parse_float is None and 347 parse_constant is None and object_pairs_hook is None and not kw):--> 348 return _default_decoder.decode(s) 349 if cls is None: 350 cls = JSONDecoder~/anaconda3/lib/python3.7/json/decoder.py in decode(self, s, _w) 335 336 """--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 338 end = _w(s, end).end() 339 if end != len(s):~/anaconda3/lib/python3.7/json/decoder.py in raw_decode(self, s, idx) 353 obj, end = self.scan_once(s, idx) 354 except StopIteration as err:--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None 356 return obj, endJSONDecodeError: Expecting value: line 1 column 1 (char 0)
添加回答
舉報
0/150
提交
取消