Python爬虫景点销售数据

此Python项目是分析景点门票销售数据,会统计出节假日哪些景点会人挤人,哪些景点值得一去。

应用介绍

import requests
import pandas as pd
from pymongo import MongoClient

class DataCrawler(object):
    def __init__(self):
        self.cities = list(pd.read_csv('city_data.csv')['city'])
        client = MongoClient(host='localhost', port=27017)
        db = client.Laborday
        self.col = db.ticket
    def get_city_trip(self):
        for city in self.cities:
            print('正在爬取城市:{}的数据!'.format(city))
            res = requests.get('https://travelsearch.fliggy.com/async/queryItemResult.do?searchType='
                               'product&keyword={}&category=SCENIC&pagenum=1'.format(city))
            data = res.json()
            itemPagenum = data['data']['data'].get('itemPagenum')
            if itemPagenum is not None:
                page_count = itemPagenum['data']['count']
                data_list = data['data']['data']['itemProducts']['data']['list'][0]['auctions']
                for ticket in data_list:
                    ticket['city'] = city
                    self.col.insert_one(ticket)
                print('成功爬取城市:{}的第{}页数据!'.format(city, 1))
                if page_count > 1:
                    for page in range(2, page_count+1):
                        res = requests.get('https://travelsearch.fliggy.com/async/queryItemResult.do?searchType='
                                           'product&keyword={}&category=SCENIC&pagenum={}'.format(city, page))
                        data = res.json()
                        data_list = data['data']['data']['itemProducts']['data']['list'][0]['auctions']
                        for ticket in data_list:
                            ticket['city'] = city
                            self.col.insert_one(ticket)
                        print('成功爬取城市:{}的第{}页数据!'.format(city, page))

if __name__ == '__main__':
    data_crawler = DataCrawler()
    data_crawler.get_city_trip()

分析景点门票销售数据,哪些景点会人挤人,哪些景点值得一去。

适合Python数据分析学习者、Python爬虫学习者、Pandas使用者、数据可视化学习者等等。

文件列表(部分)

名称 大小 修改日期
get_data.py0.69 KB2019-12-30
city_data.csv3.72 KB2019-12-30

立即下载

相关下载

[Python爬虫景点销售数据] 此Python项目是分析景点门票销售数据,会统计出节假日哪些景点会人挤人,哪些景点值得一去。

评论列表 共有 0 条评论

暂无评论

微信捐赠

微信扫一扫体验

立即
上传
发表
评论
返回
顶部