本文整理汇总了Python中model.Comment.review_id方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.review_id方法的具体用法?Python Comment.review_id怎么用?Python Comment.review_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Comment
的用法示例。
在下文中一共展示了Comment.review_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: comments
# 需要导入模块: from model import Comment [as 别名]
# 或者: from model.Comment import review_id [as 别名]
def comments(self, review_id):
'''yeild comments of a review'''
page = 1
while True:
self.logger.info('On page %s of the comments of review %s' % (page, review_id))
endpoint = 'https://www.goodreads.com/review/show.xml'
params = {'id': review_id, 'key': self.key, 'page': page}
r = requests.get(endpoint, params=params)
if r.status_code != 200:
raise GoodReadsError(r.text)
soup = BeautifulSoup(r.content, 'xml')
if int(soup.GoodreadsResponse.review.comments_count.text) == 0:
yield None
break
end = int(soup.GoodreadsResponse.review.comments['end'])
total = int(soup.GoodreadsResponse.review.comments['total'])
for comment_tag in soup.GoodreadsResponse.review.comments.find_all('comment'):
comment = Comment(int(comment_tag.id.text))
comment.body = comment_tag.body.text
try:
comment.user_id = int(comment_tag.user.id.text)
except:
comment.user_id = None
comment.review_id = int(soup.GoodreadsResponse.review.id.text)
comment.created_at = date_parser.parse(comment_tag.created_at.text)
yield comment
if end >= total:
break
page += 1