是的,您可以使用 IMDbPY 提取评论。 Colab Notebook.
# to install the imdbpy library, just including it for noob-friendliness
pip install imdbpy
这是您必须了解的有关 IMDbPY 的内容,它分别使用方法 get_movie、get_person 和 get_company 从 IMDB 检索各种对象的数据,例如电影、人物和公司。然而,事情是有很多信息要检索,检索所有内容可能不是最好的解决方案(因为它会消耗时间和带宽)。因此,数据被分组为称为“信息集”的小部分信息。
检索电影“黑客帝国 (1999)”的代码。
(注意:“0133093”是IMDb标题的ID,没有'tt',例如:https://www.imdb.com/title/tt0133093/)
from imdb import IMDb
ia = IMDb()
theMatrix = ia.get_movie('0133093')
默认情况下,电影对象具有以下信息集'main'、'plot'、'synopsis',您可以使用.current_info进行检查。现在我们可以从这里看到,默认情况下,电影对象不会检索“评论”信息集。
theMatrix.current_info
#output:
['main', 'plot', 'synopsis']
如果您知道要检索哪些信息集,我们可以将可选参数“info=”传递给 get_movie 方法。在这种情况下,“评论”。
theMatrix = ia.get_movie('0133093',['reviews'])
theMatrix.current_info
#output:
['reviews']
theMatrix['reviews']
#output:
[{'author': 'ur0540275',
'content': "The story of a reluctant Christ-like protagonist...",
'date': '19 September 2000',
'helpful': 0,
'not_helpful': 0,
'rating': 1,
'title': ''},
{'author': 'ur15794099',
'content': '** May contain spoilers **There aren\'t many movies...',
'date': '26 July 2014',
...
...
如果您已经检索了一个电影对象并希望包含更多信息集而不必再次检索整个电影对象,那么 update 方法可能会有所帮助。
theMatrix = ia.get_movie('0133093')
theMatrix.current_info
#output
['main', 'plot', 'synopsis']
ia.update(theMatrix,['reviews'])
theMatrix.current_info
#output
['main', 'plot', 'synopsis', 'reviews']
以上详述的两种方式不仅可以帮助您获得“评论”,还可以帮助您获得任何您想要检索的其他信息集。但是,您需要知道每个对象(电影、个人或公司)支持的可用信息集是什么。为此,您可以分别使用 ia.get_movie_infoset、ia.get_person_infoset 或 ia.get_company_infoset 方法。
sorted(ia.get_movie_infoset())
#output:
['airing',
'akas',
'alternate versions',
'awards',
'connections',
'crazy credits',
'critic reviews',
'episodes',
'external reviews',
...
...
'release dates',
'release info',
'reviews',
'sound clips',
'soundtrack',
'synopsis',
'taglines',
'technical',
'trivia',
'tv schedule',
'video clips',
'vote details']
有了所有这些理论,可以更好地学习和理解 imdbpy。这是获取电影评论的单线:)
ia.get_movie_reviews('0133093')
#output:
[{'author': 'ur0540275',
'content': "The story of a reluctant Christ-like protagonist...",
'date': '19 September 2000',
'helpful': 0,
'not_helpful': 0,
'rating': 1,
'title': ''},
{'author': 'ur15794099',
'content': '** May contain spoilers **There aren\'t many movies...',
'date': '26 July 2014',
...
...