python - 有没有办法使用 IMDbPY 提取 IMDb 评论?
解决方案
虽然从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
推荐阅读
- java - 在android中的custom-listview中查看问题
- python - 尽管设置正确,但媒体中的 Django 图像仍不显示
- r - 将一组行转换为R中的列
- r - 将 r 中的所有数字四舍五入,不带小数
- mysql - 如何根据列值添加标签
- apache-spark - spark的查询计划下如何
- extjs - 渲染后如何将商店添加到我的 ExtWebComponent 图表?
- apache2 - apache2 虚拟主机 html 页面链接转到默认页面
- methods - Rust 类型之谜:将函数转换为方法,调用函数的签名会破坏编译
- ios - 此应用试图在没有使用说明的情况下访问隐私敏感数据。它需要“NSLocationWhenInUseUsageDescription”