import requests
import json
url = 'http://api.map.baidu.com/telematics/v3/travel_attractions?id=yiheyuan&ak=TueGDhCvwI6fOrQnLM0qmXxY9N0OkOiQ&output=json'
rs = requests.get(url)
rs_dict = json.loads(rs.text)
error_code = rs_dict['error']
if error_code == 0:
date = rs_dict['date']
result = rs_dict['result']
name = result['name']
telephone = result['telephone']
star = result['star']
abstract = result['abstract']
description = result['description']
print('日期:%s\n景点名称:%s\n电话:%s\n星级:%s\n景点概括:%s\n景点介绍:%s\n'%(date,name,telephone,star,abstract,description))
ticket_info = result['ticket_info']
price = ticket_info['price']
open_time = ticket_info['open_time']
print('门票价格:%s\n\n开放时间:%s\n'%(price,open_time))
attention = ticket_info['attention']
detail_dict = attention[0]
name = detail_dict['name']
description = detail_dict['description']
print('优惠:%s\n优惠要求:%s\n'%(name,description))
else:
print('未查询到任何信息')
基于python的景点查询系统
最新推荐文章于 2024-07-15 10:31:42 发布
本文展示了一段使用Python代码调用百度地图API获取特定景点信息的实例。该代码通过发送HTTP请求并解析返回的JSON数据来提取景点的名称、电话、星级、简介等详细信息。此外还展示了如何获取门票价格及开放时间,并特别提到了一些优惠政策。
摘要由CSDN通过智能技术生成