本文整理汇总了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) +'×cope=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)