Twitter API:如何使用给定的 API 列表从推文文本中解析 URL

Twitter API: How to parse URL's out of the text of the tweet using the given list of API's

所以我正在使用 Python 和 Twitter API,使用 Tweepy 和 Twitter 的 Stream API,其中 returns 实时推文对象。我的应用程序的一部分查询不同的 API 与推文文本中的 URLS 不兼容,所以我使用 Python re 模块来替换它们使用无害的标识符字符串。但是,我无法找到需要从文本中解析出来的 url。我不必自己在文本中搜索 URLS,而是决定使用 API 提供的内容并在文本中执行 "find and replace"。

Here is 关于 API 给我的内容的文档。它给出了 t.co url、显示 url 和完全展开的 url。仅使用 t.co url 的问题是 twiter 不会自动将推文中的所有 url 转换为 t.co,只有超过一定长度的才会自动转换。这意味着 t.co url 并不总是出现在推文文本中的那个。

所以我需要弄清楚如何从 API 中获取实际出现在推文文本中的 URL 版本。

谢谢! evamvid

尝试将此用于 extended_url:

tweet_url = str(tweet.expanded_url) # you might not need str(), 
#test it yourself if you'd like.

# Replace tweet by the loop/function you have the json extracted with

tweet_url = tweet_url.replace('\', '')

print(tweet_url)

那你应该给你 link 而不是你想要的方式。