当前位置 : 主页 > 网络编程 > 其它编程 >

基于python的全国旅游信息查询系统(json解析)

来源:互联网 收集:自由互联 发布时间:2023-07-02
importrequestsimportjsoncityinput(请输入您要查询的城市:)urlhttp:api.map.baidu.comtelematicsv3travel_ import requestsimport jsoncity = input('请输入您要查询的城市:')url = 'http://api.map.baidu.com/telematics/v3/travel_
importrequestsimportjsoncityinput(请输入您要查询的城市:)urlhttp:api.map.baidu.comtelematicsv3travel_

import requestsimport jsoncity = input('请输入您要查询的城市:')url = 'http://api.map.baidu.com/telematics/v3/travel_city?location=%s&ak' \ '=TueGDhCvwI6fOrQnLM0qmXxY9N0OkOiQ&output=json' % cityrs = requests.get(url)rs.dict = json.loads(rs.text)error = rs.dict['error']if error == 0: date = rs.dict['date'] result_dict = rs.dict['result'] cityname = result_dict['cityname'] abstract = result_dict['abstract'] description = result_dict['description'] itineraries_list = result_dict['itineraries'] print('--------------------------------------------------------------------------------------------------------------') print('日期:%s 城市名称:%s ' % (date, cityname)) print('摘要:%s' % abstract) print('城市简介:%s' % description) print('--------------------------------------------------------------------------------------------------------------') for x_dict in itineraries_list: name = x_dict['name'] description1 = x_dict['description'] itineraries_list1 = x_dict['itineraries'] print('```````````````````````````````') print('方式:%s' % name) print('方式要点:%s' % description1) print('```````````````````````````````') for y_dict in itineraries_list1: lx = y_dict['description'] dinning = y_dict['dinning'] accommodation = y_dict['accommodation'] way_list = y_dict['path'] print('路线信息:%s' % lx) print('') print('就餐信息:%s' % dinning) print('') print('住宿信息:%s' % accommodation) print('') for fengjing in way_list: fj_name = fengjing['name'] print('行程的景点有:%s' % fj_name) print('```````````````````````````````')else: print('信息不存在')

【文章原创作者:建湖网站建设公司 http://www.1234xp.com/jianhu.html 复制请保留原URL】
上一篇:2015Beijing区域赛(KejinGame最小割)
下一篇:没有了
网友评论