之前参考别人的代码,用Python做了一个12306命令行火车票查询工具,感觉还挺有意思的!所以我做了一个类似——的携程机票查询工具。
携程官网查询效果如下:
Python命令行界面查询的效果如下:
输入出发地、目的地和航班日期,可以看到可选航班、机场、出发和到达时间、票价等信息。
视频演示效果如下:
视频加载.
该程序的源代码如下:
1.air_stations.py2.airline_ticket.py1.air_stations.py
#1.air_stations.pyimport reimport osimport jsonimport requestsfrom pprint import pprinturl='http://webresource.c-ctrip.com/code/cquery/resource/address/flight/flight_new_poi_gb2312.js CR_2017_07_18_00_00_00'response=requests.get(url,verify=False)station=re.findall(u'([\u4e00-\u9fa5]+)\(([A-Z]+)\)', response.text)stations=dict(station)pprint(stations,indent=4)2.airline_ticket.py
Query needs to specify departure date, departure city and destination city! Import requests, json, OS from doc opt import doc opt from pretty table import pretty table from colorama import init, Fore from air _ stations import stations from city=input ('Please enter the city you want to leave:') To city=input ('Please enter the city you will arrive in:') Tripdate=input ('Please enter the date (for example: 2017-09-27):') Init 6 airline flight airport time ticket price airport construction fee. Split()def _ _ init _ _(self, airline _ tickets): self. airline _ tickets=airline _ tickets @ property def plains (self): # The summary list of airlines was not found.
学点编程,有很多好处。