如何使用tweepy.Cursor和api.search从Tweepy中提取Hashtags?

7

使用 tweepy.Cursor 和 api.search 方法(如下所示),Tweepy 有效地提取了除哈希标签之外的所有其他信息。 我从文档中知道,Hashtags 存在于 Status > entities > hashtags 结构下。 我尝试在以下方法中定位“hashtags”目录,但没有成功:

print "tweet", dir(tweet)
print "////////////////"
print "tweet._api", dir(tweet._api)
print "////////////////"
print "tweet.text", dir(tweet.text)
print "////////////////"
print "tweet.entities", dir(tweet.entities)
print "////////////////"
print "tweet.author", dir(tweet.author)
print "////////////////"
print "tweet.user", dir(tweet.user)

我的代码在这里:

import tweepy

ckey = ""
csecret = ""
atoken = ""
asecret = ""

OAUTH_KEYS = {'consumer_key':ckey, 'consumer_secret':csecret,
    'access_token_key':atoken, 'access_token_secret':asecret}
auth = tweepy.OAuthHandler(OAUTH_KEYS['consumer_key'], OAUTH_KEYS['consumer_secret'])
api = tweepy.API(auth)

for tweet in tweepy.Cursor(api.search, q=('"good book"'), since='2014-09-16', until='2014-09-17').items(5):

    print "Name:", tweet.author.name.encode('utf8')
    print "Screen-name:", tweet.author.screen_name.encode('utf8')
    print "Tweet created:", tweet.created_at
    print "Tweet:", tweet.text.encode('utf8')
    print "Retweeted:", tweet.retweeted
    print "Favourited:", tweet.favorited
    print "Location:", tweet.user.location.encode('utf8')
    print "Time-zone:", tweet.user.time_zone
    print "Geo:", tweet.geo
    print "//////////////////"
2个回答

6

1
我得到了空结果,API 有什么变化吗? - Fabian Bosler

4

我没有足够的声望发表评论,但是可以回答Fabian Bosler的问题 - 由于entities是一个字典,请尝试:

tweet.entities['hashtags']

这对我有帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接