Tweepy光标搜索 - 用户输入和提及

问题描述 投票:1回答:1

我正在尝试在tweepy的api.search函数中进行用户输入搜索和设置搜索参数。

基本上我想要这样:

print("input search term to search within Tesla tweets")
keyword = input()
print("Thanks!")
print("Tweets are cooking in the background now...")


# create list to append tweets to
tweets = []

# append all tweet data to list
for tweet in tweepy.Cursor(api.search, q="@tesla" + keyword, tweet_mode="extended", count=10000, 
                       since="2018-08-01").items():
    tweets.append(tweet)
    word_string = repr(tweet)

但这不起作用它只是不返回任何推文

所以我已经尝试过这样的功能,但它会在推文中返回@tesla的内容,而不是提到特斯拉的推文,所以它并不理想 -

print("input search term to search within Tesla tweets")
keyword = input() + "@Tesla"
print("Thanks!")
print("Tweets are cooking in the background now...")

tweets = []

for tweet in tweepy.Cursor(api.search, keyword, tweet_mode="extended", count=10000, 
                       since="2018-08-01").items():
    tweets.append(tweet)
    word_string = repr(tweet)

有什么方法可以做第一个选择,或者我只需要忍受它,它不是主要的,所以如果是这样的话,这不是什么大问题?

谢谢!

python twitter tweepy
1个回答
0
投票

我找到了一个更容易解决这个问题的方法,不知道如何关闭这个问题,但我想我会给出一个答案以供参考,以防有人遇到同样的问题:)

事实证明,除非你有一个高级的Twitter开发帐户,否则你不能使用布尔运算符。

所以我只是做了@tesla搜索,把它放到pandas数据帧中,然后我过滤了用户输入搜索词的pandas数据帧。更容易做,但限制我的搜索条件是唯一的警告。

© www.soinside.com 2019 - 2024. All rights reserved.