首页 > 解决方案 > 有没有办法使用 IMDbPY 提取 IMDb 评论?

问题描述

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

https://imdbpy.github.io/

标签: pythonweb-scrapingimdbimdbpy

解决方案


虽然从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

推荐阅读