使用 Tweepy 时如何将 link 删除到推特 post?

How can you remove the link to the twitter post when using Tweepy?

我做了一个非常简单的函数,它只打印给定用户的最新推文:

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,这将打印:

“在将四名宇航员发射到...之前,39A 号发射场的机库中的龙和猎鹰 9 号机组人员 https://t.co/ cnkLRu8R08”(添加 space 因为 SO 不允许缩短 links)

但是,我想删除 link 放在最后的推文

试试这个:

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