使用 tweepy 保存推文的全文 [英] Save full text of a tweet with tweepy
问题描述
我是 Python 的新手程序员.我在尝试使用 tweepy
提取一系列推文的文本并将其保存到文本文件时遇到了麻烦(我省略了身份验证和其他内容)
I am a novice programmer in python. I am having troubles trying to extract the text of a series of tweets with tweepy
and saving it to a text file (I ommit the authentication and stuff)
search = api.search("hello", count=10)
textlist=[]
for i in range(0,len(search)):
textlist.append( search[i].text.replace('\n', '' ) )
f = open('temp.txt', 'w')
for i in range(0,len(idlist)):
f.write(textlist[i].encode('utf-8') + '\n')
但在一些长推文中,末尾的文本被截断,每个字符串的末尾会出现一个三点字符...",所以有时我会丢失链接或主题标签.我怎样才能避免这种情况?
But in some long tweets the text at the end is truncated, and a three dot character "..." appears at the end of each string, so sometimes I lose links or hashtags. How can I avoid this?
推荐答案
这是转发的默认行为.您可以在 retweeted_status
对象下访问全文.
This is default behaviourfor retweets. You can access the full text under the retweeted_status
object.
关于更改的 Twitter API 实体部分:
Twitter API entities section about the change:
https://dev.twitter.com/overview/api/entities-in-twitter-objects#retweets
Twitter API 文档(查找截断")
Twitter API documentation (look for "truncated")
https://dev.twitter.com/overview/api/tweets
这篇关于使用 tweepy 保存推文的全文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!