当前位置: 首页>>代码示例>>Python>>正文


Python Movie.decode_content方法代码示例

本文整理汇总了Python中movie.Movie.decode_content方法的典型用法代码示例。如果您正苦于以下问题:Python Movie.decode_content方法的具体用法?Python Movie.decode_content怎么用?Python Movie.decode_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在movie.Movie的用法示例。


在下文中一共展示了Movie.decode_content方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Controller

# 需要导入模块: from movie import Movie [as 别名]
# 或者: from movie.Movie import decode_content [as 别名]
class Controller(object):
    """docstring for Controller"""
    def __init__(self, movie_name):
        super(Controller, self).__init__()
        self.session = login()
        self.movie_name = movie_name
        self.movie = Movie(self.movie_name, self.session)

    def start(self):
        start_time = datetime.datetime.strptime(START_TIME, '%Y-%m-%d-%H')
        end_time = datetime.datetime.strptime(END_TIME, '%Y-%m-%d-%H')
        if start_time < end_time:
            while True:
                time.sleep(3)
                cursor_time = start_time + datetime.timedelta(hours=1)
                timescope = datetime.datetime.strftime(start_time, '%Y-%m-%d-%H') +':' + datetime.datetime.strftime(cursor_time, '%Y-%m-%d-%H')
                url = 'http://s.weibo.com/weibo/'+ quote(self.movie_name) +'&timescope=custom:'+ quote(timescope)
                response = self.session.get(url)
                count = self.get_page_count(response.content)
                self.handle_one_page(url, count, self.movie.id)
                start_time = cursor_time
                if start_time > end_time:
                    break
        else:
            print 'ERROR:Start time must early than end time!'

    def get_page_count(self, content):
        max_count = 0
        result = re.findall(r'&page=\d+', content)
        for index in result:
            info = index.split('=')
            if int(info[1]) > max_count:
                max_count = int(info[1])
        print 'max_page:', max_count
        return max_count

    def handle_one_page(self, url_head, page_count, movie_id):
        for i in xrange(1, page_count + 1):
            page = str(i)
            url = url_head +"&page=" + page
            response = self.session.get(url)
            self.movie.decode_content(response.content, movie_id)
            print "现在是第%s页" % page
            time.sleep(3)
开发者ID:ChainBoy,项目名称:WorkFile-Sonidigg,代码行数:46,代码来源:movie_main.py


注:本文中的movie.Movie.decode_content方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。