赞
踩
欢迎大家点赞、收藏、关注、评论啦 ,由于篇幅有限,只展示了部分核心代码。
随着我国旅游业的不断发展,名宿作为一种新型而具有特色的接待形式,通过温馨而亲民的方式为游客提供了更加具有地方特色的旅游体验。本项目利用网络爬虫技术从去哪儿网采集名宿酒店数据,并进行数据清洗和格式化,利用 flask 搭建后台,前端利用 echarts 等实现对名宿酒店的各类属性分布进行可视化分析。
功能主要包括:
利用python 执行 curl 命令,抓取某旅游平台的名宿酒店住宿数据:
total_count = 0 total_hotels = [] for cmd in curl_cmds: cmd = cmd.replace('\\', '') resp = os.popen(cmd) resp = resp.read() resp = json.loads(resp) hotels = resp['data']['hotels'] for hotel in hotels: hotel_info = { "name": hotel['name'], "price": hotel['price'], "roomType": hotel['roomType'], "score": hotel['score'], "locationInfo": hotel['locationInfo'], "imageid": hotel['imageid'], "etag": hotel['etag'] if 'etag' in hotel else '暂无', "dangciText": hotel['dangciText'], "commentDesc": hotel['commentDesc'] if 'commentDesc' in hotel else '好', "commentCount": hotel['commentCount'], } total_hotels.append(hotel_info) total_count += len(hotels) # 保存数据 with open('hotel_info.json', 'w', encoding='utf8') as fout: fout.writelines([json.dumps(line, ensure_ascii=False) + '\n' for line in total_hotels])
随着我国旅游业的不断发展,名宿作为一种新型而具有特色的接待形式,通过温馨而亲民的方式为游客提供了更加具有地方特色的旅游体验。本项目利用网络爬虫技术从去哪儿网采集名宿酒店数据,并进行数据清洗和格式化,利用 flask 搭建后台,前端利用 echarts 等实现对名宿酒店的各类属性分布进行可视化分析。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。