【问题标题】:Twitter API (Tweepy) how to get exact termsTwitter API (Tweepy) 如何获取准确的术语
【发布时间】:2017-09-19 03:23:34
【问题描述】:

所以我试图在 Twitter API(tweepy 包装器)中搜索包含特定单词的推文。但是,在搜索单词时,我得到的结果很接近。 (即搜索“there”但 tweepy 返回“there's”。有没有办法用 tweepy 指定你想要的确切术语。

我的部分代码:

otherTweet = tweepy.Cursor(api.search, q=word and hashtag, count=1, lang="en").items(1) # searches for words needed to retweet later
    for a in otherTweet:
        ref = a.text.encode("unicode-escape")
        if "#" in ref and word not in ref.split(" ") or not otherTweet:
            otherTweet = tweepy.Cursor(api.search, q=word, count=1, lang="en").items(1) # Can't find tweet with right hashtag. 
            print "got here"

word 和 hashtag 都是变量,例如 word = "hello" hashtag = "#blessed"。我假设我对他们做了一些事情以获得特定条款。

【问题讨论】:

    标签: python python-2.7 twitter tweepy


    【解决方案1】:

    要仅搜索特定字词并删除任何其他字词,您需要在搜索字词周围添加空格。搜索“there”或“there”而不是“there”。

    还有更复杂的路线,例如对前后字符进行二次检查,但这是我在应用程序中发现的最快和最有用的路线。

    【讨论】:

    • 我试过了,但是好像没什么影响。仍然得到诸如“那里!”之类的东西。可能不得不尝试第二个选项。
    • 我从不担心标点符号,我认为这就是问题所在(twitter 单词搜索 api 可能会将标点符号视为搜索的空格)。如果是这种情况,第二个选项是您最好的选择,但应该很难实施。 .split() 是你要找的东西,应该只需要一个额外的逻辑块来修复。
    • 是的,你是对的,似乎没有考虑标点符号。分裂是我最后不得不做的。有点烦人,但总比没有好。
    猜你喜欢
    • 2018-03-07
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 2014-03-19
    • 2022-12-07
    • 2016-07-29
    • 2020-02-02
    • 2013-06-15
    相关资源
    最近更新 更多