【发布时间】:2019-01-14 00:36:22
【问题描述】:
我想根据特定的 Hashtag 提取数据/推文。除了“#LetsTaxThis”之外,我的 python 代码适用于任何主题标签。主要是我想用来从推特中提取数据的主题标签。
使用此标签运行代码后,我只能看到 2 条推文,但已经有 1000 多条带有此标签的推文。
我的 CONSUMER_KEY 、 CONSUMER_SECRET 、 ACCESS_TOKEN 和 ACCESS_SECRET 没问题。因为其他主题标签正在起作用。
import tweepy # To consume Twitter's API
import pandas as pd # To handle data
import numpy as np # For number computing
# For plotting and visualization:
from IPython.display import display
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
# Twitter App access keys for @user
# Consume:
CONSUMER_KEY = '--------'
CONSUMER_SECRET = '----------------'
# Access:
ACCESS_TOKEN = '--------------'
ACCESS_SECRET = '-------------'
#------------------
# We import our access keys:
from credentials import * # This will allow us to use the keys as variables
# API's setup:
def twitter_setup():
"""
Utility function to setup the Twitter's API
with our access keys provided.
"""
# Authentication and access using keys:
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
# Return API with authentication:
api = tweepy.API(auth)
return api
------------------
# We create an extractor object:
extractor = twitter_setup()
# We create a tweet list as follows:
#tweets = extractor.user_timeline(screen_name="@iamsrk", count=600)
tweets = extractor.search(q="#letsTaxThis", count=200)
print("Number of tweets extracted: {}.\n".format(len(tweets)))
# We print the most recent 5 tweets:
#print("3 recent tweets:\n")
for tweet in tweets[:3]:
print(tweet.text)
print()
-----------------------
期待您的回音:)。
提前致谢:)
【问题讨论】:
标签: python-3.x twitter data-science