程序员人生 网站导航

新浪微博数据挖掘食谱之六: 元素篇 (提取微博元素)

栏目:互联网时间:2015-01-06 08:14:00
#!/usr/bin/python # -*- coding: utf⑻ -*- ''' Created on 2015⑴⑵ @author: beyondzhou @name: extract_weibo_entities.py ''' # Extract entities of sina weibo def extract_weibo_entities(): # import from login import weibo_login from statuses import extract_weibo_entities import json # Access to sina api weibo_api = weibo_login() # Get public timeline public_timeline = weibo_api.statuses.public_timeline.get(count=200) # Output the public timeline # print json.dumps(public_timeline, indent=1) # Extract entities (status_texts,screen_names,reposts_count,comments_count,retweeted_status,words) status_texts,screen_names,reposts_count,comments_count,retweeted_status,words = extract_weibo_entities(public_timeline) ''' print json.dumps(status_texts, indent=1, ensure_ascii=False) print json.dumps(screen_names, indent=1) print json.dumps(reposts_count, indent=1) print json.dumps(comments_count, indent=1) print json.dumps(retweeted_status, indent=1) print json.dumps(words, indent=1) ''' entityDict = {'status_texts':status_texts, 'screen_names':screen_names, 'reposts_count':reposts_count, 'comments_count':comments_count, 'retweeted_status':retweeted_status, 'words':words} for key in entityDict: print ' Information of %s' % key print json.dumps(entityDict[key], indent=1, ensure_ascii=False) if __name__ == '__main__': extract_weibo_entities()

# Extract weibo entities def extract_weibo_entities(statuses): # Extracting text, screen names, reposts_count, comments_count, retweeted_status from weibo status_texts = [status['text'] for status in statuses] screen_names = [status['user']['screen_name'] for status in statuses] reposts_count = [status['reposts_count'] for status in statuses] comments_count = [status['comments_count'] for status in statuses] retweeted_status = [status['retweeted_status'] for status in statuses if status.has_key('retweeted_status')] # Compute a collection of all words from all weibo words = [w for t in status_texts for w in t.split()] return status_texts,screen_names,reposts_count,comments_count,retweeted_status,words

Result:

callback_url: https://api.weibo.com/oauth2/authorize?redirect_uri=http%3A//apps.weibo.com/guaguastd&response_type=code&client_id=2925245021 return_redirect_uri: http://weibo.com/login.php?url=http%3A%2F%2Fapps.weibo.com%2Fguaguastd%3Fcode%3D1a3b5b2e8c4458fe1f9a872cb41ed6cf code: ['1a3b5b2e8c4458fe1f9a872cb41ed6cf'] Information of reposts_count [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] Information of retweeted_status [] Information of status_texts [ "我刚给@郑容和89 赠送了1朵鲜花,取得了2倾慕值,感觉自己萌萌哒!饭圈的亲们,快来送花应援吧!http://t.cn/R7FzA9e", "起来就被自己吓到………", "搭配要点:白色T恤+千鸟格短裤+蓝色西装外套+黑色单位+黑色皮鞋+黑色软呢帽。", "防城港!", "发钱啦!@angelababy 正在发红包,总共117633元现金。手快有,手慢无! http://t.cn/Rzki6jW", "发钱啦!@湖南卫视 正在发红包,总共600000元现金。手快有,手慢无! http://t.cn/RZU44L0", "#微乐#定之荞 袋装荞麦精粉 1kg(价格:13.9元),我的生活我定制 ----来自微乐客户端 http://t.cn/RZbsHwi ", "我忽然喜欢上这1个人的日子,虽然说有点孤单,但过得惬意,我想做甚么就做甚么,喜欢吃甚么就吃甚么,自己怎样高兴怎样来[嘻嘻]", "[闪电] 链接:http://t.cn/RzsnrZY", "#Twings和Tasty1直在1起#心疼他们", "#微乐#广济两路 板鸭 1500g/2只装(价格:67元)包邮 微笑生活,快乐分享http://t.cn/RZbsHAt ", "#东方卫视跨年#新年我最荣幸,2015我最红!元旦我在@angelababy 和@东方卫视番茄台 送出的红包中抽到了“1元现金”! 还在等甚么,快来试试吧!http://t.cn/Rzki6jW", "搭配示范:中袖白色数字棒球服+深蓝色高腰牛仔短裤+黑色板鞋+蓝色帆布包。亲,#开网店啦亲#【技术+货源+发货+售后】全程指点#轻松教你做网店#!你只需要1台电脑或手机就能够开启你的网店之旅 每天两个小时上网时间便可,上万种货源供你选择,有兴趣咨询QQ:603471295", "今天我在#百词斩# 背了40个雅思核心单词。世上只有妈妈好?我妈逼我背单词。 你也来背单词吧 >>> http://t.cn/zYFwdTq #百词斩学霸认证#", "#大神X7#1直很期待", "魔羯座 本日(1月2日)综合运势:★★★★★,荣幸色彩:金色,荣幸数字:5,速配星座:金牛座(分享自@微心情) 查看更多: http://t.cn/hBDFW", "被子里 好冷[生病]", "魔羯座 本日(1月2日)综合运势:★★★★★,荣幸色彩:金色,荣幸数字:5,速配星座:金牛座(分享自@微心情) 查看更多: http://t.cn/hBDFW", "【盛夏最易受诱惑出轨的星座男】第1名:射手座。盛夏来临,花心的射手们会孤单难耐,对各路美女都没有抵抗力。第2名:天秤座。天秤男天生就不晓得谢绝其他人,应当说他们来者不拒,特别是美女。第3名:白羊座。白羊男喜欢接受挑战,特别是那些特别难驯服的女人。", "魔羯座 本日(1月2日)综合运势:★★★★★,荣幸色彩:金色,荣幸数字:5,速配星座:金牛座(分享自@微心情) 查看更多: http://t.cn/hBDFW", "【郑秀文承认与许志安同居 还没有注册结婚】9月12日讯,郑秀文11日亮相某珠宝↓活动,被问是不是已正式成为“许太”,郑秀文称两人已1起生活,彼此认定,所以只差“注册”这个法律程序。", "克东 今天(1月2日)天气:晴,⑵2℃~⑴6℃,西风≤3级,空气质量:轻度 (分享自@微心情) http://t.cn/zT7OEhx", "啊!!到底要我肿么样··· http://t.cn/RZbsHAQ", "宝应 今天(1月2日)天气:晴转多云,⑴℃~8℃,东风3⑷级转≤3级,空气质量:优 (分享自@微心情) http://t.cn/zT700iw", "分享自正义无敌 《购买城市楼房和农村住宅建设中的毛病风水认识》 - 酷爱风水的朋友们,大家好在视察了多年的城市楼房购买和农村住宅建设中我总结了人们在购买楼房和住宅建设中多数人形... (来自 @头条博客) - http://t.cn/R7CH9LZ ", "[载歌载舞]【你合适跟谁在1起 】听说经过这个测试的情侣不会分手;你和她将是最完善的酸碱中和,永久在1起。大家都来验证1下吧!(详见下图)[啦啦][逗号]不要轻易的去放弃1个每天都是会去想念的人。这样的人,那末你1辈子也是不会再遇到几个的", "吉林 今天(1月2日)天气:晴,⑴8℃~⑴1℃,微风≤3级转3⑷级,空气质量:优 (分享自@微心情) http://t.cn/zT7NhKW", "弥勒 今天(1月2日)天气:阴转多云,8℃~18℃,微风≤3级,空气质量:轻度 (分享自@微心情) http://t.cn/zT70Cdz", "很多绝食减肥的人碰到了这类现象:没有减肥之前只是没有注意控制热量,却没有暴食现象。绝食1段时间以后对食品的愿望明显增加,暴食的时候感觉特别爽,这是为何呢?", "天秤座 本日(1月2日)综合运势:★★★☆☆,荣幸色彩:灰色,荣幸数字:6,速配星座:魔羯座(分享自@微心情) 查看更多: http://t.cn/zRf0I5z", "吼吼吼~嘿嘿嘿~嘻嘻嘻 http://t.cn/RZbsHZm", "魔羯座 本日(1月2日)综合运势:★★★★★,荣幸色彩:金色,荣幸数字:5,速配星座:金牛座(分享自@微心情) 查看更多: http://t.cn/hBDFW", "繁昌 今天(1月2日)天气:晴,⑴℃~10℃,东风≤3级,空气质量:轻度 (分享自@微心情) http://t.cn/zT7OZuJ", "我刚在实惠APP里抢到1份福利:E洗车上门洗车服务,荣幸要和小火伴们分享,你也快来试试吧!http://t.cn/RhHaqbx @实惠APP", " 我们只不过是从上1辈人那里剪切过来了1个人生 然后不断地进行复制 粘贴 连刷新都没有 ", "终究把DRIVE的进度追上了……不过对新出场的2骑完全5感,我的心已完全偏到反派那边去了,不知道为何就是想看heart吃瘪,chase和brain却很招人疼的感觉_(:з」∠)_", "安平 今天(1月2日)天气:晴转霾,⑹℃~5℃,西熏风≤3级,空气质量:轻度 (分享自@微心情) http://t.cn/zT70CJo", "It's funny how day by day, nothing ch¹anges. But when you look back, everything is different. ~~~ 可笑的是,时间1每天过,好像甚么也没改变,但当你回头看,每件事都变了。", "http://t.cn/RzClUtJ", "The best relationship is when you can completely act yourself and they can still love you for who you are.最好的爱情是,你可以完全地做自己,并且你的另外一半仍然迷恋真实的你。", "有时候,让他人在意你的最好办法,就是不那末在意他。", "答应自己,强大起来,那样就没有甚么事能扰乱你平静的心灵。把烦恼,对折,对折,再对折,最后浓缩成快乐;把快乐,扩大,扩大,再扩大,最后扩大成幸福源泉。把时光,对折,对折,再对折,瞬间幸福就来了;把祝愿熔化,熔化,再熔化,最后熔化成人间佳话。【精选语录】", "There’s no real love in you. Why do I keep loving you? 你没有真爱,我为什么还要继续爱你?", "#东方卫视跨年#元旦天上掉红包啦,我在@angelababy 和@东方卫视番茄台 共同送出的红包里抽到了“0.2元现金”!想和我1样么?速来抽元旦红包吧!http://t.cn/Rzki6jW", " 万年企盼本日到,挣断红索启归航,这里有方向 http://t.cn/Rzds8bm ", "我参与了@我是歌手 发起的投票【【#我是歌手#重要投票】新生代歌手你希望谁来踢馆?】,我投给了“#我是歌手#@庄心妍Ada”等2个选项。你也快来表态吧:http://t.cn/RZbUL9n", "难得休息,可是刚刚连做梦,都梦见自己在下乡。[汗]", "[挖鼻屎] 地 址 :http://t.cn/RZyz8lz", "《秦时明月》破秦兵百万,做秦时霸王 http://t.cn/RZPg11y", "[
------分隔线----------------------------
------分隔线----------------------------

最新技术推荐