tweepy - 如何使用 tweepy 获取推文的全文?
问题描述
我正在使用 tweepy.Cursor 提取特定主题的过去推文,但是如果推文真的很长,它会截断它。我正在使用 full_text 属性为 True,但它仍然无法修复它。如何解决这个问题?
我的代码在这里:
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
API = tweepy.API(auth)
csvFile = open('tweets2.csv', 'a')
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(API.search,q="$EURUSD",count=1000,
lang="en", full_text = True).items():
csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8')])
csvFile.close()
解决方案
您必须显式访问名为“full_text”的字段。你可以尝试这样的事情:
# First you get the tweets in a json object
results = [status._json for status in tweepy.Cursor(API.search, q="$EURUSD", count=1000, tweet_mode='extended', lang='en').items()]
# Now you can iterate over 'results' and store the complete message from each tweet.
my_tweets = []
for result in results:
my_tweets.append(result["full_text"])
您可以根据需要提取尽可能多的信息,然后将其写入 CSV 文件或任何您想要的文件。
我建议您将推文提取到 json 文件中,以便您可以轻松检查它提供给您的所有字段。
希望能帮助到你!
编辑:如果检索到的推文是 RT,则全文将在 result["retweeted_status"]["full_text"]
推荐阅读
- blazor - Blazor 中的动态编辑表单
- vb.net - 将单个字符串中的所有组合设为两位数
- npm - 安装adonis cli时出现警告
- python - 无法导入 appscript python 模块
- python - python-rq:工作人员很忙,但 current_job 不存在
- python - 使用Flask单击按钮后无法打开html
- python - 需要帮助使用 firebase 流式休息 api 不起作用
- c++ - 没有要调用的匹配函数:错误:必须使用 '.*' 或 '->*' 来调用 'f (...)' 中的指向成员函数的指针,例如 '(... ->* f) ( ...)'
- c# - 从 C# 代码调用存储过程返回 -1
- google-apps-script - Google Drive 第三方快捷方式的工作原理