这里发现
一只程序猿O(∩_∩)O
渴望用Hello World改变世界,喜欢电影,喜欢跑步,略带文艺的逗比程序猿一只!

猫眼电影票房数据,抓了一个多星期,差不多了,分享出来

前段时间开始抓电影数据,豆瓣的数据还没有整理,先把猫眼的分享出来。没有自己写爬虫,用的pyspider,想了解爬虫,可以看这篇文章《Python爬虫的工具列表整理

下面是爬虫的代码,不得不说Pyspider做的很不错,只是性能优化的不太好,这里就不详细介绍了,改天详细总结一下。

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2015-12-25 14:57:29
# Project: maoyan
import re
from pyspider.libs.base_handler import *
class Handler(BaseHandler):
    @every(minutes=24 * 60)
    def on_start(self):
        for i in range(1, 1000):
            self.crawl('http://piaofang.maoyan.com/movie/'+str(i), callback=self.detail_page)
    @config(age=24*60*60, priority=1)
    def detail_page(self, response):
        myurl = response.url.split('/')
        nextId = int(myurl[len(myurl)-1])+999
        if nextId<400000:
            self.crawl('http://piaofang.maoyan.com/movie/'+str(nextId), callback=self.detail_page)
        if len(response.doc('#ticket_tbody > ul'))==0:
            return{}
        return {
            "maoyan_id":myurl[len(myurl)-1],
            "title":response.doc('body > header > h1').text(),
            "movie_office":[x.text() for x in response.doc('#ticket_tbody > ul').items()],
        }
 

下面的是猫眼的数据,json格式,实际用的话需要自己写脚本处理一下。

MaoYanData Download

转载请注明出处fullstackdevel.com:SEAN是一只程序猿 » 猫眼电影票房数据,抓了一个多星期,差不多了,分享出来

分享到:更多 ()

Comment 抢沙发

评论前必须登录!