# -*- coding: utf-8 -*-
import pypyodbc
import requests
from bs4 import BeautifulSoup
#获取access文件中的记录,filepath路径,tablename表名
def get_rows_from_mdb(filepath,tablename):
conn = pypyodbc.connect(u'Driver={Microsoft Access Driver (*.mdb)};DBQ=' + filepath)
cur = conn.cursor()
try:
cur.execute('select * from %s ' % tablename)
records = cur.fetchall()
except:
print '读取文件失败'
return records
#调用百度地图API接口,address为地名,ak为百度秘钥
def getlocation(address,ak):
try:
baseurl = 'http://api.map.baidu.com/geocoder/v2/?address='
myak = '&ak=' + ak
url = baseurl + address + myak
response = requests.get(url)
responseinfo = response.content
soup = BeautifulSoup(responseinfo,'lxml')
lng = soup.lng.string
lat = soup.lat.string
location = lng + ',' + lat
except:
location = 'UNKWON'
return location
yy = get_rows_from_mdb('E:/qqq.mdb','b1')
output = open('data.txt', 'w+')
fields = '字段1'+','+'字段2'+','+'字段3'+','+'字段4'
output.write(fields+'\n')
for y in yy:
print y[0],y[1],y[2]
rowline = str(y[0]) + ',' + y[1] + ',' +y[2]
output.write(rowline+'\n')
output.close()
#xx = getlocation('babb路','dte7eUyXPMwEqhn6xb66HbxVaBrNpkab')
地理编码(待重构)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 在获取用户位置时候,Core Location 会返回一对经纬度。我们人类看不出什么东东,但是存在就是合理,交给机...