加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

大数据汇报你:10年漫威,到底有几多脚色

发布时间:2019-05-15 01:00:49 所属栏目:教程 来源:小F
导读:最近正值复联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') 

(编辑:湖南网)

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

热点阅读