1. login to their Renren network, enter the web page http://friend.renren.com/myfriendlistx.do#item_0, get such as the page:
Right-click to view the source code, copy a line from your friends list, and save it as myfriends. dat (save as a line of text ).
2. Run the source code:
import urllib,urllib2,cookielibimport redef MyFriends(filename): patt2='"id":(\d+),"vip":[\s\S]+?"name":"([\s\S]+?)",\"head":"([\s\S]+?)","groups":\["([\s\S]+?)"\]' #id,name,head,groups patt='"id":(\d+),' f=open(filename,'r') for eachLine in f: friendList=re.findall(patt,eachLine) return friendListdef Login(t,JSESSIONID): cookie={'t':t,'JSESSIONID':JSESSIONID} cookies=''.join(x+'='+cookie[x]+';' for x in cookie) return cookiesdef ShareFriends(cookies,friendID): opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(\ cookielib.CookieJar())) urllib2.install_opener(opener) req = urllib2.Request('http://friend.renren.com/shareFriends?\t=0.8142646627966315&p={"init":true,"uid":true,"uhead":true,\"uname":true,"group":true,"net":true,\"param":{"guest":'+friendID+'}}') req.add_header('Cookie', cookies) content = urllib2.urlopen(req).read() patt='"id":(\d+),"netName":"' friends=re.findall(patt,content) return friendsdef AllFriendsLinkCSV(cookies,friendList,filename): f=open(filename,'w') f.write('Source,Target\n') for friendID in friendList: f.write('xxxx,'+friendID+'\n') # replace XXXX with your ID for friendID in friendList: friends=ShareFriends(cookies,friendID) for ID in friends: f.write(friendID+','+ID+'\n') f.close() def main(): friendList=MyFriends('myFriends.data2') t,JSESSIONID='xxxxx','xxxxx' cookies=Login(t,JSESSIONID) AllFriendsLinkCSV(cookies,friendList,'FriendsLink.csv') if __name__=='__main__': main()
The myfriends function is used to obtain a list of friends.
Mutual friends is used to obtain mutual friends with a friend.
Allfriendslinkcsv saves the friend relationship as a CSV file in the format specified by gephi.
In the main function, after obtaining the T and JSESSIONID in the following way, replace XXXXX In the above Code:
Right-click on the Renren page, review elements, and red overwrites under resource options
3. Replace the T and JSESSIONID values and run the above code to get friendslink.csv. Follow the steps below to import CSV files in gephi:
Back to the overview page, you can see the network diagram:
After a series of operations, you can get your own social graphs ~
References:
[1] Everybody cookie login: http://www.guokr.com/post/317472/
Gephi Chinese Tutorial: https://www.udemy.com/gephi
[3] Social Network Analysis Course on Coursera: https://www.coursera.org/course/sna