最近珠海公交公司出了一個手機app查詢公交車,可是優化作得很差,總是感受卡,不爽,本身無聊就寫了一個python版的,方便下珠海市民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'您輸入的有誤'
執行看下結果:app
[root@zh rh]# python bus.py
請輸入公交站路線:35
請輸入公交車:招商花園城
雲頂瀾山 到 跨境工業區 路線
公交車已經到招商花園城站
距離您還有0站
#########################
跨境工業區 到 雲頂瀾山 路線
公交車已經到隧道南站
距離您還有5站
實現了,可是仍是不方便,應該在手機上面能實現就好,因而就找了不少資料,python fro iphone,可是安裝了,卻沒有lxml這個模塊,以失敗了結
iphone