簡體   English   中英

使用 Tweepy 庫搜索推文

[英]Search for tweets with Tweepy library

我一直在使用 Python 的 Tweepy 庫提取帶有關鍵字的推文。 直到最近我才注意到我的數據庫包含這樣的推文: tweet example

我搜索了“臭氧洞”,它返回了一條推文,其文本實際上並不包含“臭氧洞”,但可以在新聞標題中找到“臭氧洞”,推文的作者對此進行了引用。

有什么方法可以避免這樣的推文並搜索在實際推文文本中包含我的關鍵字的推文?

我搜索推文的代碼塊:

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(...)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM