码迷,mamicode.com
首页 > 编程语言 > 详细

Python 提取LinkedIn用户的人脉

时间:2014-08-18 06:59:53      阅读:375      评论:0      收藏:0      [点我收藏+]

标签:数据挖掘   linkedin   

CODE:

#!/usr/bin/python 
# -*- coding: utf-8 -*-

'''
Created on 2014-8-18
@author: guaguastd
@name: linkedin_connection_retrieve.py
'''

# import login
from login import linkedin_login

# import json
import json
from prettytable import PrettyTable

# access to linkedin api
linkedin_api = linkedin_login()

connections = linkedin_api.get_connections()
connections_data = r'E:\eclipse\LinkedIn\dfile\linkedin_connections.json'

# Write connections into disk file
f = open(connections_data, 'w')
f.write(json.dumps(connections, indent=1))
f.close()

# Read data from disk file
connections = json.loads(open(connections_data).read())

# Print the connections
#print json.dumps(connections, indent=1)
pt = PrettyTable(field_names=['Name', 'Location'])
pt.align = 'l'

[pt.add_row((c['firstName'] + ' ' + c['lastName'], c['location']['name']))
 for c in connections['values']
     if c.has_key('location')]

print pt

RESULT:

+-------------------------+----------------------------+
| Name                    | Location                   |
+-------------------------+----------------------------+
| 飞 黄                   | Beijing City, China        |
| James Liao              | San Francisco Bay Area     |
| Gerald Soparkar         | San Francisco Bay Area     |
| Dimitrios Kouzis-Loukas | Birmingham, United Kingdom |
| Xiaodong Xu             | Beijing City, China        |
| Xinsong Li              | China                      |
| 科技 后院               | Chengdu, Sichuan, China    |
| 彦超 胡                 | Xingtai, Hebei, China      |
| 诺克 埃                 | Beijing City, China        |
| Zhang Jason             | Beijing City, China        |
| qu Sisyphus             | United States              |
| 洪林 张                 | Foshan, Guangdong, China   |
| beyond Bzhou            | United States              |
+-------------------------+----------------------------+


Python 提取LinkedIn用户的人脉,布布扣,bubuko.com

Python 提取LinkedIn用户的人脉

标签:数据挖掘   linkedin   

原文地址:http://blog.csdn.net/guaguastd/article/details/38654785

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!