python分析推特_Python 提取Twitter转发推文的元素(比方username)

使用Python进行Twitter分析,通过login模块获取访问权限,利用search模块进行搜索,并使用extract_retweet_id和get_rt_attributions函数获取转发推文的ID和归属信息。用户输入查询关键词,例如'Core Python',程序展示相应转发推文的归属用户。
摘要由CSDN通过智能技术生成

CODE:

#!/usr/bin/python

# -*- coding: utf-8 -*-

'''

Created on 2014-7-24

@author: guaguastd

@name: extract_retweet_attributions.py

'''

if __name__ == '__main__':

# import login, see http://blog.csdn.net/guaguastd/article/details/31706155

from login import twitter_login

# get the twitter access api

twitter_api = twitter_login()

# import search

from search import twitter_search

# import extract_retweet_id

from tweet import extract_retweet_id, get_rt_attributions

while 1:

query = raw_input('\nInput the query (eg. #MentionSomeoneImportantForYou, exit to quit): ')

if query == 'exit':

print 'Successfully exit!'

break

search_results = twitter_search(twitter_api, query, max_results=1)

#print search_results,

# Get the retweet id

retweets_id = extract_retweet_id(search_results)

#print retweets_id,

# Get the retweet attribution

for rid in retweets_id:

tweet = twitter_api.statuses.show(_id=rid)

print get_rt_attributions(tweet)

print

RESULT:

Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): Core Python

Length of statuses 60

[u'ritzylivingwage']

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值