python wifi接口_基于Python的全国WIFI接口调用代码实例

代码描述:基于Python的全国WIFI接口调用代码实例

关联数据:全国WIFI

接口地址:http://www.juhe.cn/docs/api/id/18

1.[代码][Python]代码

#!/usr/bin/python

# -*- coding: utf-8 -*-

import json, urllib

from urllib import urlencode

#----------------------------------

# 全国WIFI调用示例代码 - 聚合数据

# 在线接口文档:http://www.juhe.cn/docs/18

#----------------------------------

def main():

#配置您申请的APPKey

appkey = "*********************"

#1.查询周边WIFI

request1(appkey,"GET")

#2.按城市查询WIFI

request2(appkey,"GET")

#查询周边WIFI

def request1(appkey, m="GET"):

url = "http://apis.juhe.cn/wifi/local"

params = {

"lon" : "", #经纬(如:121.538123)

"lat" : "", #纬度(如:31.677132)

"gtype" : "", #所传递经纬类型 1:百度 2:谷歌 3:gps

"r" : "", #搜索范围,单位M,默认3000

"key" : appkey, #应用APPKEY(应用详细页查询)

"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"

#按城市查询WIFI

def request2(appkey, m="GET"):

url = "http://apis.juhe.cn/wifi/region"

params = {

"city" : "", #城市名urlencode utf8;

"page" : "", #页数,默认1

"key" : appkey, #应用APPKEY(应用详细页查询)

"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"

if __name__ == '__main__':

main()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值