1

我不需要 Kaggle 中提供的数据集。我想使用 IMDbPY 或任何其他抓取方法从 IMDb 中提取电影评论。

https://imdbpy.github.io/

4

2 回答 2

2

虽然从imdbpy 文档中并不明显。您始终可以通过检查变量的键来检查变量的属性。当您使用 imdbpy 抓取电影时,并非您要查找的所有信息都立即可用。在您的情况下,您希望获得评论。所以你必须添加它们。我们可以在信息集中看到,有三种不同类型的评论;“评论”、“外部评论”和“评论评论”。与这些关联的键尚未添加。下面的示例显示了它是如何完成的。

from imdb import IMDb

# create an instance of the IMDb class
ia = IMDb()

the_matrix = ia.get_movie('0133093')
print(sorted(the_matrix.keys()))

# show all information sets that can be fetched for a movie
print(ia.get_movie_infoset()) #Information we can add. Keys will be added
ia.update(the_matrix, ['external reviews'])
ia.update(the_matrix, ['reviews'])
ia.update(the_matrix, ['critic reviews'])
# show which keys were added by the information set
print(the_matrix.infoset2keys['external reviews']) #no external reviews, so no key is added
print(the_matrix.infoset2keys['reviews']) # A lot of reviews. Adds key: 'reviews'
print(the_matrix.infoset2keys['critic reviews']) #Adds the keys: 'metascore', and 'metacritic url'
# print(the_matrix['reviews'])
print(sorted(the_matrix.keys())) #Check out the new keys that we have added
于 2020-01-29T16:54:18.400 回答
1

是的,您可以使用 IMDbPY 提取评论。Colab 笔记本

# 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',
...
...

如果您已经检索了一个电影对象并且想要包含更多信息集而不必再次检索整个电影对象,那么更新方法可能会有所帮助。

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',
...
...
于 2020-04-22T07:28:35.173 回答