¿我为Metacritic开发了一个网络剪贴簿,我得到了评论,但现在我必须改变我的方式,我必须在一个地方有好评(8-10),中立评论(5-8)和差评(1-5)。当我把这三个类别的评论分开时,我该怎么办呢!?
urls = ['https://www.metacritic.com/game/pc/league-of-legends/user-reviews']
def scrape_metacritic(self, urls):
"""
Public method that extracts all the reviews given a list of Metacritic URLS
:param urls:
:return:
"""
data = []
for url in urls:
start = 0
next = 1
while start < next:
html = self.__make_request(url + f'user-reviews?page={str(start)}')
blocks = self.__div_blocks(html)
reviews = self.__get_comments(blocks)
if len(reviews) is 0:
start = next
else:
for review in reviews:
data.append(review)
start += 1
next += 1
return data
这个功能是什么?
你最好使用列表字典......就像
data = {'bad': [], 'neutral': [], 'good': []}
然后,当您遍历评论时,您会附加到正确的列表中。
if review.score < 8 and review.score > 4:
data['neutral'].append(review)