使用 Tweepy 库搜索推文
Search for tweets with Tweepy library
我一直在使用 python 的 Tweepy 库提取带有关键字的推文。
直到最近我才注意到我的数据库中包含这样的推文:
tweet example。
我搜索了"ozone hole",它返回了一条推文,其文本实际上不包含"ozone hole",但可以在新闻标题中找到"ozone hole",其中推文的作者做了参考。
有什么方法可以避免出现这样的推文并搜索在实际推文文本中包含我的关键字的推文吗?
我搜索推文的代码块:
for tweet in tweepy.Cursor(api.search,
q="ozone hole",
lang="en",
#Since="2019-11-27",
#until="2019-11-14",
tweet_mode='extended').items():
这就是 Twitter 搜索的工作原理。如果您通过 Twitter 的网站搜索相同的查询,您会发现它会得出相同的结果。
不过请注意,这可能是由于查询显示在 URL 本身,而不是该网站的标题中。
首先尝试使用这些命令来查找您要查找的日期:
unitl= datetime.date.today()
print("Today's date:", until)
since= until- datetime.timedelta(days=50) #the number isdentify the number of days that you are looking for the tweets
print(since)
那么你可以使用下面的命令来指定关键字
tweets_list = tweepy.Cursor(...)
我一直在使用 python 的 Tweepy 库提取带有关键字的推文。 直到最近我才注意到我的数据库中包含这样的推文: tweet example。
我搜索了"ozone hole",它返回了一条推文,其文本实际上不包含"ozone hole",但可以在新闻标题中找到"ozone hole",其中推文的作者做了参考。
有什么方法可以避免出现这样的推文并搜索在实际推文文本中包含我的关键字的推文吗?
我搜索推文的代码块:
for tweet in tweepy.Cursor(api.search,
q="ozone hole",
lang="en",
#Since="2019-11-27",
#until="2019-11-14",
tweet_mode='extended').items():
这就是 Twitter 搜索的工作原理。如果您通过 Twitter 的网站搜索相同的查询,您会发现它会得出相同的结果。
不过请注意,这可能是由于查询显示在 URL 本身,而不是该网站的标题中。
首先尝试使用这些命令来查找您要查找的日期:
unitl= datetime.date.today()
print("Today's date:", until)
since= until- datetime.timedelta(days=50) #the number isdentify the number of days that you are looking for the tweets
print(since)
那么你可以使用下面的命令来指定关键字
tweets_list = tweepy.Cursor(...)