本文整理汇总了Python中movie.Movie.set_rating方法的典型用法代码示例。如果您正苦于以下问题:Python Movie.set_rating方法的具体用法?Python Movie.set_rating怎么用?Python Movie.set_rating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类movie.Movie
的用法示例。
在下文中一共展示了Movie.set_rating方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DoubanHtmlParser
# 需要导入模块: from movie import Movie [as 别名]
# 或者: from movie.Movie import set_rating [as 别名]
class DoubanHtmlParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
# If True, the content of this tag is a movie entry.
self._output_entry = False
# If this tag is closed, finish this movie entry.
self._output_entry_finish_tag = ''
# If True, the content of this tag is movie name.
self._start_movie_name = False
# If True, the content of this tag is movie intro.
self._start_intro = False
# If True, the content of this tag is movie viewing date.
self._start_date = False
# If True, store next content in _current_data
self._grab_data = False
# If this tag is encountered, finish current entry/attributes
# and update current movie object.
self._output_finish_tag = ''
# A list of movie object
self._movie_list = []
# Current discovered movie object
self._movie = None
# a buffer storing data.
self._current_data = ''
def reset(self):
HTMLParser.reset(self)
# Reser clears movie list
self._movie_list = []
def clear(self):
# clear all the states of current movie.
# Prepare for next movie entry.
self._output_entry = False
self._output_entry_finish_tag = ''
self._start_movie_name = False
self._start_intro = False
self._start_date = False
self._grab_data = False
self._output_finish_tag = ''
self._current_data = ''
self._movie = None
# Invoked when a html start tag is parsed.
def handle_starttag(self, tag, attrs):
if tag == 'div':
for attr in attrs:
if attr[0] == 'class' and attr[1] == 'info':
# <div class="info"> starts a new movie entry.
self._output_entry = True
self._movie = Movie()
self._output_entry_finish_tag = tag
elif self._output_entry:
if tag == 'li':
for attr in attrs:
if attr[0] == 'class' and attr[1] == 'title':
# <li class="title"> includes movie name
self._start_movie_name = True
elif attr[0] == 'class' and attr[1] == 'intro':
# <li class="intro"> includes movie intro
self._output_finish_tag = tag
self._grab_data = True
self._start_intro = True
elif tag == 'span':
for attr in attrs:
if attr[0] == 'class' and attr[1] == 'date':
# <span class="date"> includes movie view date.
self._output_finish_tag = tag
self._grab_data = True
self._start_date = True
#TODO
# watched list has
# <dev class="info">
# everything
# </dev>
# but wish list has
# <dev class="info">
# movie info
# </dev>
# <li>
# entry creation day
# </li>
if attr[0] == 'class' and attr[1].find('rating') >= 0:
# <span class="ratingX-t"> has rating information.
def GetRating(s):
return ((s.split('rating'))[1].split('-'))[0]
self._movie.set_rating(int(GetRating(attr[1])))
elif self._start_movie_name and tag == MOVIE_NAME_START_TAG:
# movie name tag is encountered. Store next data.
self._output_finish_tag = tag
self._grab_data = True
#.........这里部分代码省略.........