我从文件中读取了更多的千位坐标,因为我希望得到相关的国家/地区。我试图杀死时间限制,但它还没有工作,它在150-160坐标后停止。我能处理吗?
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
with open('alagridsor.txt') as f:
lines = f.read().splitlines()
for sor in range(1, 9271):
print(sor)
koor = lines[sor]
from geopy.geocoders import Nominatim
from geopy.exc import GeocoderTimedOut
geolocator = Nominatim()
location = geolocator.reverse(koor, timeout=None)
cim = location.raw['address']['country']
print(cim)
f = open('out.txt', 'a')
f.write(cim.encode('utf8'))
f.write("\n")
答案 0 :(得分:2)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
from geopy.geocoders import Nominatim
geolocator = Nominatim(timeout=None)
fobj_out = open('out.txt', 'a')
with open('alagridsor.txt') as fobj_in:
for koor in fobj_in:
location = geolocator.reverse(koor.rstrip())
cim = location.raw['address']['country']
fobj_out.write(cim.encode('utf8'))
fobj_out.write("\n")
time.sleep(0.5) # delay 5 milli-seconds between each request
fobj_out.close()