Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有一种方法可以使用IMDbPY提取IMDb评论?_Python_Web Scraping_Imdb_Imdbpy - Fatal编程技术网

Python 有没有一种方法可以使用IMDbPY提取IMDb评论?

Python 有没有一种方法可以使用IMDbPY提取IMDb评论?,python,web-scraping,imdb,imdbpy,Python,Web Scraping,Imdb,Imdbpy,我不需要数据集,它在Kaggle中可用。我想使用IMDbPY或任何其他刮削方法从IMDb中提取电影评论 虽然从照片上看不明显。您总是可以通过检查变量的键来检查变量的属性。当您使用imdbpy抓取电影时,并非所有要查找的信息都会立即可用。在你的情况下,你想得到评论。所以你必须加上它们。我们可以在信息集中看到,有三种不同类型的评论;'评论、外部评论和评论家评论。尚未添加与这些关联的键。下面的示例显示了如何执行此操作 from imdb import IMDb # create an instanc

我不需要数据集,它在Kaggle中可用。我想使用IMDbPY或任何其他刮削方法从IMDb中提取电影评论


虽然从照片上看不明显。您总是可以通过检查变量的键来检查变量的属性。当您使用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

虽然从表面上看并不明显。您总是可以通过检查变量的键来检查变量的属性。当您使用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

是的,您可以使用IMDbPY提取评论

以下是您必须了解的关于IMDbPY的内容,它分别使用get_movie、get_person和get_company方法从IMDB中检索各种对象(如电影、人物和公司)的数据。然而,问题是有很多信息需要检索,检索所有信息可能不是最好的解决方案(因为这会耗费时间和带宽)。因此,数据被分组为称为“信息集”的小部分信息。

用于检索电影“矩阵(1999)”的代码。
(注:“0133093”是不带“tt”的IMDb标题ID,示例:)

默认情况下,电影对象具有以下信息集“main”、“plot”、“synopsis”,您可以使用.current\u 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\u movie\u infoset、ia.get\u person\u infoset或ia.get\u company\u 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。以下是获得电影评论的一句话:)


是的,您可以使用IMDbPY提取评论

以下是您必须了解的关于IMDbPY的内容,它分别使用get_movie、get_person和get_company方法从IMDB中检索各种对象(如电影、人物和公司)的数据。然而,问题是有很多信息需要检索,检索所有信息可能不是最好的解决方案(因为这会耗费时间和带宽)。因此,数据被分组为称为“信息集”的小部分信息。

用于检索电影“矩阵(1999)”的代码。
(注:“0133093”是不带“tt”的IMDb标题ID,示例:)

默认情况下,电影对象具有以下信息集“main”、“plot”、“synopsis”,您可以使用.current\u 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\u movie\u infoset、ia.get\u person\u infoset或ia.get\u company\u 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。以下是获得电影评论的一句话:)


嘿,你试过代码了吗?如果是这样,请分享你所拥有的,我们可以从中开始帮助你。()通过浏览文档和源代码,该库似乎不允许访问评论。它可能藏在那里的某个地方though@byxor肯定有。但它有点隐蔽。但这只是不确定我们从imdb下载的数据是否比需要的多。嘿,你试过代码了吗?如果是这样,请分享你所拥有的,我们可以从中开始帮助你。()通过浏览文档和源代码,该库似乎不允许访问评论。它可能藏在那里的某个地方though@byxor肯定有。但它有点隐蔽。但这只是不确定我们从imdb下载的数据是否超过需要。