如何解决使用Tweepy时如何删除指向Twitter帖子的链接?
我做了一个非常简单的功能,它仅打印给定用户的最新推文:
def get_tweet(username):
recent_tweets = self.twitter_api.user_timeline(username,page = 1)
# I turn it into a string in order to remove the b' and ' at the beginning and end
print(f"@{username}'s latest tweet is: \n{str(recent_tweets[0].text)[2:-1]}")
说的用户名是SpaceX
,将显示:
“在将4名宇航员发射到……https://t.co/ cnkLRu8R08之前,在39A号发射场的机库中乘载了Dragon and Falcon 9”(添加了空格,因为SO不允许缩短链接)
但是,我想删除到末尾的推文的链接
解决方法
尝试一下:
def get_tweet(username):
recent_tweets = self.twitter_api.user_timeline(username,page = 1)
s = f"@{username}'s latest tweet is: \n{str(recent_tweets[0].text.encode("utf-8"))[2:-1]}"
s = s.split()
del s[-1]
print(s)
get_tweet()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。