- #!/usr/bin/python
- #-*- coding:utf-8 -*-
- """
- 根据地区进行探测,并进行日志打印,防止出错重新开始;并设置了简单的速度处理
- 作者:索隆
- """
- import time
- import urllib2
- import logging.config
- logging.config.fileConfig("logging.conf")
- log = logging.getLogger('number')
- with open("result.txt") as rf:
- with open("latlng.txt","a+") as wf:
- results = []
- for num,line in enumerate(rf.readlines(),1):
- if num%100 == 0:
- log.info(str(num))
- if num%2000 == 0:
- wf.writelines(results)
- wf.flush()
- results = []
- # time.sleep(20*60)
- # time.sleep(15)
- time.sleep(0.5)
- response = urllib2.urlopen("http://ditu.google.cn/maps/geo?q=%s&output=csv"%(line.split("\\t"))[2].strip())
- html = response.read().decode("gbk").encode("utf-8")
- results.append(html+'\\n')
- print html
- #该片段来自于http://www.codesnippet.cn/detail/140620134046.html
来源: http://www.codesnippet.cn/detail/140620134046.html