gpt4 book ai didi

python - 使用 tweepy 保存推文的全文

转载 作者:行者123 更新时间:2023-11-28 21:15:52 24 4
gpt4 key购买 nike

我是 python 的新手程序员。我在尝试使用 tweepy 提取一系列推文的文本并将其保存到文本文件时遇到了麻烦(我忽略了身份验证和其他内容)

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')

但在一些长推文中,末尾的文本被截断,每个字符串的末尾出现一个三点字符“...”,所以有时我会丢失链接或主题标签。我怎样才能避免这种情况?

最佳答案

使用 tweepy,您可以使用 tweet_mode='extended' 获取全文(未记录在 Tweepy 文档中)。例如:

(未扩展)

print api.get_status('862328512405004288')._json['text']

@tousuncotefoot @equipedefrance @CreditAgricole @AntoGriezmann @KMbappe @layvinkurzawa @UmtitiSam J'ai jamais vue d… https://tco/kALZ2ki9Vc

(扩展)

print api.get_status('862328512405004288', tweet_mode='extended')._json['full_text']

@tousuncotefoot @equipedefrance @CreditAgricole @AntoGriezmann @KMbappe @layvinkurzawa @UmtitiSam J'ai jamais vue de match de foot et cela ferait un beau cadeau pour mon copain !! 🙏🏻🙏🏻🙏🏻😍😍

关于python - 使用 tweepy 保存推文的全文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29588177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com