加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 运营中心 > 网站设计 > 教程 > 正文

大数据告诉你:10年漫威,到底有多少角色

发布时间:2019-05-15 09:50:38 所属栏目:教程 来源:小F
导读:副标题#e# 最近正值复联4上映,小F也发现了一个有趣的网站。 主要是关于漫威人物、漫威电影的图谱。 https://graphics.straitstimes.com/STI/STIMEDIA/Interactives/2018/04/marvel-cinematic-universe-whos-who-interactive/index.html(复制到浏览器打开)
副标题[/!--empirenews.page--]

最近正值复联4上映,小F也发现了一个有趣的网站。

主要是关于漫威人物、漫威电影的图谱。

https://graphics.straitstimes.com/STI/STIMEDIA/Interactives/2018/04/marvel-cinematic-universe-whos-who-interactive/index.html(复制到浏览器打开)

网站是基于Graph技术开发的。

其实之前小F也利用了有关Graph的库实现了一波人物的关系分析。

只不过分析结果比较粗糙而已~

下面是网站的概况,大家可以一览。

大数据告诉你:10年漫威,到底有多少角色

 大数据告诉你:10年漫威,到底有多少角色

那么人家能做出这么酷炫的关系图,我们自己能不能实现呢?

这一期就利用网站提供的数据,使用Neo4j(NOSQL图形数据库)进行实战一波。

一、获取分析

人物及人物关联信息从网站上获取,具体接口如下。

大数据告诉你:10年漫威,到底有多少角色

数据为json格式,分别在「characters」和「relationship」中。

大数据告诉你:10年漫威,到底有多少角色

这里的信息是分别指托尼·斯达克,关系「0」为朋友,斯蒂文·罗杰斯。

大数据告诉你:10年漫威,到底有多少角色

二、 数据获取

具体代码如下。

  1. headers = { 
  2.     'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' 
  3.  
  4. url = 'https://graphics.straitstimes.com/STI/STIMEDIA/Interactives/2018/04/marvel-cinematic-universe-whos-who-interactive/data/marvel-data.json' 
  5. response = requests.get(url=url, headers=headers) 
  6. result = json.loads(response.text) 
  7.  
  8. num = 0 
  9. names = [] 
  10. item = {0: 'friend', 1: 'enemy', 2: 'creation', 3: 'family', 4: 'work', 5: 'love'} 
  11.  
  12. for i in result['relationship']: 
  13.     subject = result['relationship'][i]['id'] 
  14.     object = result['relationship'][i]['target_id'] 
  15.  
  16.     if subject not in names: 
  17.         names.append(subject) 
  18.     if object not in names: 
  19.         names.append(object) 
  20.  
  21.     relation = int(result['relationship'][i]['relationship']) 
  22.     with open('relation_message.csv', 'a+') as f: 
  23.         f.write(subject + ',' + object + ',' + item[relation] + 'n') 
  24.  
  25. for j in names: 
  26.     num += 1 
  27.     with open('names_message.csv', 'a+') as f: 
  28.         f.write(j + ',' + str(num) + 'n') 
  29.  
  30. for k in result['characters']: 
  31.     id = result['characters'][k]['id'] 
  32.     name = result['characters'][k]['name'] 
  33.     status = result['characters'][k]['status'] 
  34.     species = result['characters'][k]['species'] 
  35.     with open('message.csv', 'a+') as f: 
  36.         f.write(id + ',' + name + ',' + status + ',' + species + 'n') 

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读