链家二手房爬虫和获取经纬度

匿名 (未验证) 提交于 2019-12-02 23:26:52

获取经纬度

import json from urllib.request import urlopen, quote import pandas as pd import csv   xlsx_1 = pd.ExcelFile('bbhu.xlsx') data1 = xlsx_1.parse('Sheet2')  url = 'http://api.map.baidu.com/geocoder/v2/' output = 'json' ak = 'raSWR0VKik7******shHzFH' s = data1['小区'] jkdu = [] wwdu = []  # 创建一个worksheet for i in s:     try:         add = quote(i)         uri = url + '?' + 'address=' + add  + '&output=' + output + '&ak=' + ak #百度地理编码API         req = urlopen(uri)         res = req.read().decode()         temp = json.loads(res)         jkdu.append(temp['result']['location']['lng'])         wwdu.append(temp['result']['location']['lat'])#打印出经纬度     except OSError:         pass     continue                result = [] length = len(jkdu) for i in range(length):     result.append(str(s[i])+' '+str(jkdu[i])+' '+str(wwdu[i]))   with open('xiaoqujkww.csv', 'a', newline='', encoding='utf-8')as f:     write = csv.writer(f)     for data in result:         write.writerow([data])     f.close() 

文章来源: https://blog.csdn.net/weixin_43139613/article/details/88871620
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!