Twitter API (Tweepy) 如何获得确切的条款
Twitter API (Tweepy) how to get exact terms
所以我试图在 Twitter API(tweepy 包装器)中搜索包含特定单词的推文。但是,在搜索单词时,我得到的结果很接近。 (即搜索 "there" 但 tweepy returns "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"。我假设我对他们做了一些事情以获得特定条款。
为了仅搜索特定字词并删除任何其他字词,您需要在搜索字词周围添加空格。搜索 "there " 或“那里”而不是 "there"。
还有更复杂的路线,如对前后字符进行二次检查,但这是我在应用程序中找到的最快、最有用的路线。
所以我试图在 Twitter API(tweepy 包装器)中搜索包含特定单词的推文。但是,在搜索单词时,我得到的结果很接近。 (即搜索 "there" 但 tweepy returns "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"。我假设我对他们做了一些事情以获得特定条款。
为了仅搜索特定字词并删除任何其他字词,您需要在搜索字词周围添加空格。搜索 "there " 或“那里”而不是 "there"。
还有更复杂的路线,如对前后字符进行二次检查,但这是我在应用程序中找到的最快、最有用的路线。