【问题标题】:Excluding link at the end while pulling tweets in tweepy Streaming在 tweepy Streaming 中拉推文时在末尾排除链接
【发布时间】:2020-12-12 17:56:05
【问题描述】:

我正在使用 tweepy 流媒体拉动 textextended_text,但是当我拉动这些推文时,末尾总是有一个 t.co/randomletters 链接,导致无处可去。它是什么,我该如何摆脱它? 这是一个例子:

 "text": "To make room for more expression, we will now count all emojis as equal—including those with gender‍‍‍ ‍‍and skin tone modifiers https://t.co(forward slash)MkGjXf9aXm"

请帮忙

【问题讨论】:

    标签: python api twitter streaming tweepy


    【解决方案1】:

    就我使用 twitter 和 tweepy 的经验而言,只要实际推文中存在某种 URL,这些 URL 就会包含在推文的文本中,因此我们无法避免获取它们。

    您可以在获得它们后将其删除,这是一个简单的正则表达式,可将这些 URL 的模式替换为空白字符串。

    import re
    
    re.sub(r' https://t.co/\w{10}', '', tweet_text)
    

    【讨论】:

    • 哦,对了——当推文中有视频或照片时,它是否还包括url?
    • 是的,如果真的有纯文本以外的内容,您将在 API 响应中获得此表单的 URL。
    猜你喜欢
    • 2015-06-27
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    相关资源
    最近更新 更多