python 查询珠海公交车到站情况(显示距离版)

   最近珠海公交公司出了一个手机app查询公交车,但是优化做得不好,老是感觉卡,不爽,自己无聊就写了一个python版的,方便下珠海市民


# coding=utf8
from lxml import etree
bus=int(raw_input('请输入公交站路线:'))
bus_zd=raw_input('请输入公交车:')
url="http://zhgj.zhuhai.gd.cn:8090/BusTransfer/brewMobile/queryArrivalForetell?lineName=%s路&stationName=%s" % (bus,bus_zd)
tree=etree.parse(url)
root=tree.getroot()
if(root.__len__() > 3):
    start_bus = root[3][4].text
    end_bus = root[3][5].text
    now_bus = root[3][6].text
    you_bus =  root[3][9].text
    print u'%s  到  %s 路线' % (start_bus,end_bus)
    print u'公交车已经到%s站' % now_bus
    print u'距离您还有%s站' % you_bus
    print '#########################'
    h_start_bus = root[4][4].text
    h_end_bus = root[4][5].text
    h_now_bus = root[4][6].text
    h_you_bus =  root[4][9].text
    print u'%s  到  %s 路线' % (h_start_bus,h_end_bus)
    print u'公交车已经到%s站' % h_now_bus
    print u'距离您还有%s站' % h_you_bus
else:
    print u'您输入的有误'



执行看下结果:

[root@zh rh]# python bus.py
请输入公交站路线:35
请输入公交车:招商花园城
云顶澜山  到  跨境工业区 路线
公交车已经到招商花园城站
距离您还有0站
#########################
跨境工业区  到  云顶澜山 路线
公交车已经到隧道南站
距离您还有5站

实现了,但是还是不方便,应该在手机上面能实现就好,于是就找了很多资料,python fro iphone,但是安装了,却没有lxml这个模块,以失败告终

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章