Python 通过调用接口获取公交信息的实例

今天小编就为大家分享一篇Python 通过调用接口获取公交信息的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

如下所示:

 # -*- coding: utf-8 -*- import sys, urllib, urllib2, json city=urllib.quote(sys.argv[1]); url = 'http://apis.baidu.com/xiaota/bus_lines/buses_lines?city=%s&bus=%s&direction=%s'%(city,sys.argv[2],sys.argv[3]) print url req = urllib2.Request(url) req.add_header("apikey", "2f5da4b87cbd02a5f8be1189db99b6a8") resp = urllib2.urlopen(req) content = resp.read() if(content):     print(content) print "\n" busStation = json.loads(content) print busStation.keys() print busStation['data'].keys() print busStation['data']['stations'] for bus in busStation['data']['stations']:         print bus['stateName'] 

以上这篇Python 通过调用接口获取公交信息的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持html中文网。

以上就是Python 通过调用接口获取公交信息的实例的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python