基于Python的房地产数据接口调用代码实例 代码描述:基于Python的房地产数据接口调用代码实例 代码平台:聚合数据 #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode #---------------------------------- # 地产数据调用示例代码 - 聚合数据 # 在线接口文档:http://www.juhe.cn/docs/47 #---------------------------------- def main(): #配置您申请的APPKey appkey = "*********************" #1.地产检索 request1(appkey,"GET") #2.周边地产 request2(appkey,"GET") #3.支持城市列表 request3(appkey,"GET") #地产检索 def request1(appkey, m="GET"): url = "http://v.juhe.cn/estate/query" params = { "city" : "", #城市名称,请参考支持城市列表 "key" : appkey, #应用APPKEY(应用详细页查询) "q" : "", #地产名关键字 "page" : "", #页数,默认1,每页返回10条 "dtype" : "", #返回数据的格式,xml或json,默认json } params = urlencode(params) if m =="GET": f = urllib.urlopen("%s?%s" % (url, params)) else: f = urllib.urlopen(url, params) content = f.read() res = json.loads(content) if res: error_code = res["error_code"] if error_code == 0: #成功请求 print res["result"] else: print "%s:%s" % (res["error_code"],res["reason"]) else: print "request api error" #周边地产 def request2(appkey, m="GET"): url = "http://v.juhe.cn/estate/local" params = { "lat" : "", #纬度(百度地图坐标系) "lng" : "", #经度 "radius" : "", #检索半径,默认5000 单位米 "key" : appkey, #应用APPKEY(应用详细页查询) "page" : "", #页数,默认1,每页返回20条 "dtype" : "", #返回数据的格式,xml或json,默认json } params = urlencode(params) if m =="GET": f = urllib.urlopen("%s?%s" % (url, params)) else: f = urllib.urlopen(url, params) content = f.read() res = json.loads(content) if res: error_code = res["error_code"] if error_code == 0: #成功请求 print res["result"] else: print "%s:%s" % (res["error_code"],res["reason"]) else: print "request api error" #支持城市列表 def request3(appkey, m="GET"): url = "http://v.juhe.cn/estate/citys" params = { } params = urlencode(params) if m =="GET": f = urllib.urlopen("%s?%s" % (url, params)) else: f = urllib.urlopen(url, params) content = f.read() res = json.loads(content) if res: error_code = res["error_code"] if error_code == 0: #成功请求 print res["result"] else: print "%s:%s" % (res["error_code"],res["reason"]) else: print "request api error" if __name__ == '__main__': main() 本文来源:https://www.wddqw.com/doc/74a38dc103d8ce2f006623eb.html