我正在使用tweepy库编写一个代码来收集包含特定用户id的所有tweet
为了实现这样的目标(假设我可以访问twitter API),我会做如下工作:
import pandas as pd
import numpy as np
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from tweepy import API
from tweepy import Cursor
auth = OAuthHandler(twitter_credentials['CONSUMER_KEY'], twitter_credentials['CONSUMER_SECRET'])
auth.set_access_token(twitter_credentials['ACCESS_TOKEN'], twitter_credentials['ACCESS_TOKEN_SECRET'])
api = API(auth,wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
# Search word/hashtag value
HashValue = '_austrian'
# search start date value. the search will start from this date to the current date.
StartDate = "2019-11-11" # yyyy-mm-dd
for tweet in Cursor(api.search,q=HashValue,count=1,lang="en",since=StartDate, tweet_mode='extended').items():
print (tweet.created_at, tweet.full_text)
然而,这种方法似乎没有回报我的期望。我刚收到一系列的推特,上面提到了奥地利语。你知道吗
我应该怎么做才能得到包含奥地利语的tweet?你知道吗
我要做的是改用这个包:GetOldTweets3
我使用了以下代码。你知道吗
目前,它将查找所有包含给定日期的'\u austrian'的tweet,并限制在代码上搜索10条tweet。根据需要调整。你知道吗
要循环浏览结果,您需要循环它。你知道吗
样本输出
您可以在github页面上阅读更多关于如何控制搜索的内容。使用这个包可以获得的不仅仅是用户名和内容。你知道吗
相关问题 更多 >
编程相关推荐