难以按人口统计提取IMDb评级(使用IMDbpy)

时间:2017-11-13 22:11:43

标签: python imdb imdbpy

我想按人口统计(性别,年龄组)收集IMDb评分详情。

当我尝试在imdbpy中使用get_movie_vote_details模块时,我的输出为空。 这是我的代码:

 import imdb

 i =  imdb.IMDb(accessSystem='http')

 movie = i.get_movie('0780504')

 print(movie)

 votes = i.get_movie_vote_details('0780504')

 print(votes)

这是输出:

print(m)

  

驱动器

print(votes)

  

{'charactersRefs':{},'data':{},'namesRefs':{},'titlesRefs':{}}

正如你所看到的,“投票”输出有点偏差。有没有办法可以使用imdbpy提取评级详细信息?

1 个答案:

答案 0 :(得分:2)

您不应该直接调用 .get_movie_XYZ(...)方法:它们在内部用于使用 IMDb()。update更新Movie实例(... )方法。

例如:

import imdb

i = imdb.IMDb(accessSystem='http')

movie = i.get_movie('0780504')
i.update(movie, 'vote details')
print(movie.get('mean and median')

如果您想了解所有可用的信息集,请致电i.get_movie_infoset();要查看更新给定信息集时添加了Movie实例的哪些键,请使用movie.infoset2key映射。

有关详细信息,请参阅official documentation

关于数据的格式,此代码:

from imdb import IMDb
ia = IMDb()
m = ia.get_movie('0780504', 'vote details')
print('median', m.get('median'))
print('arithmetic mean', m.get('arithmetic mean'))
print('number of votes', m.get('number of votes'))
print('demographics', m.get('demographics'))

将输出如下内容: median 8 arithmetic mean 7.8 number of votes {1: 8626, 2: 4135, 3: 5762, 4: 9264, 5: 17595, 6: 39440, 7: 84746, 8: 133331, 9: 98870, 10: 75737} demographics {'imdb staff': {'rating': 7.8, 'votes': 36}, 'aged under 18': {'rating': 8.5, 'votes': 844}, 'non us users': {'rating': 7.8, 'votes': 250586}, 'top 1000 voters': {'rating': 7.6, 'votes': 739}, 'males aged 45 plus': {'rating': 7.4, 'votes': 24213}, 'aged 45 plus': {'rating': 7.4, 'votes': 28779}, 'aged 18 29': {'rating': 7.9, 'votes': 183217}, 'us users': {'rating': 8.0, 'votes': 71299}, 'aged 30 44': {'rating': 7.7, 'votes': 181063}, 'males aged under 18': {'rating': 8.5, 'votes': 705}, 'males aged 30 44': {'rating': 7.8, 'votes': 152988}, 'females aged under 18': {'rating': 7.9, 'votes': 133}, 'males aged 18 29': {'rating': 8.0, 'votes': 148749}, 'females aged 45 plus': {'rating': 7.4, 'votes': 4004}, 'imdb users': {'rating': 7.8, 'votes': 477506}, 'females aged 18 29': {'rating': 7.6, 'votes': 32575}, 'females': {'rating': 7.6, 'votes': 65217}, 'males': {'rating': 7.9, 'votes': 341617}, 'females aged 30 44': {'rating': 7.5, 'votes': 25465}}