python-3.x - 根据特定的标签提取数据/推文

标签 python-3.x twitter data-science

我想根据特定的标签提取数据/推文。除了“#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()

    -----------------------

期待您的来信:)。

提前致谢:)

最佳答案

搜索 API 仅返回一周前的推文。您需要获得批准才能使用高级搜索 API 来获取较早的推文。

关于python-3.x - 根据特定的标签提取数据/推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51717995/

相关文章:

html - Twitter 嵌入式时间轴 100% 宽度

python - 如何处理数据集中的匿名变量以获得更好的预测

r - 为模型选择实现 LOOCV(不使用 caret 包)

python - cv2.approxPolyDP() , cv2.arcLength() 这些是如何工作的

python - 我应该使用什么shebang来始终指向python3?

python-3.x - 使用 tkinter、MVC 和 Observables 设置 Entry 的值

python - 如何从输出中删除不需要的 '\n'

Python 3 通过索引从 json 获取值

css - 如何放大 Twitter 按钮?

node.js - TypeError : Cannot create property '_id' on string. ..即使在使用 JSON.Parse 之后? (MongoDB/Node.js/Twitter API)