#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib.request
import urllib.parse
import xlrd
from xlrd import open_workbook
import xlwt
import xlutils
import datetime
from xlutils.copy import copy
import sys
import json
import time
def testXlrd(filename):
book = xlrd.open_workbook(filename)
sh = book.sheet_by_index(0)
print(sh.nrows, sh.ncols)
for rownum in range(2, 759):
row = sh.row_values(rownum)[0]
print(row)
requestLBS(filename, row, rownum)
def requestLBS(filename, name, rownum):
time.sleep(2)
url = "http://if.xqwy.cn/community/search"
postdata = urllib.parse.urlencode({
"deviceId":"00000000-04e6-7d39-28fe-a7f40033c587",
"appVersion":"4.6",
"longitude":"121.538163",
"version":"1.0.0",
"pageSize":"10",
"keyword":name,
"city":"苏州",
"latitude":"31.296207",
"page":"1"
}).encode("utf-8")
req = urllib.request.Request(url,postdata)
req.add_header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36")
data = urllib.request.urlopen(req).read()
jsonstr = json.loads(data)
msg = jsonstr['message']
if msg == None:
communities = jsonstr['data']['communities']
for i in range(len(communities)):
for key,value in communities[i].items():
#print(key,value)
if key == "longitude":
print("longitude: "+ str(value))
testXlwt(filename,str(value),rownum,8)
if key == "latitude":
print("latitude: " + str(value))
testXlwt(filename,str(value),rownum,9)
# longitudestr = json.loads(communities)
# longitude = longitudestr['longitude']
# print(longitude)
# latitude = jsonstr['data']['communities']['latitude']
# fhandle = open("/Users/xunwang/Desktop/ftx.txt", "wb")
# fhandle.write(longitude + ","+ latitude)
# fhandle.close()
def testXlwt(filename, strs, rownum, index):
book = xlrd.open_workbook(filename)
sh = book.sheet_by_index(0)
wsh = copy(book)
wsh2 = wsh.get_sheet(0)
wsh2.write(rownum, index, strs)
wsh.save(filename)
print(" 写入表成功" + str(rownum))
if __name__=='__main__':
testXlrd("/Users/xunwang/Desktop/yuanqu.xls")
请求接口获得房屋地理位置
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...