简体   繁体   English

使用 Tweepy 库搜索推文

[英]Search for tweets with Tweepy library

I've been doing extraction of tweets with keywords using Tweepy library for python.我一直在使用 Python 的 Tweepy 库提取带有关键字的推文。 It's been only recently that I've noticed that my database include tweets like this: tweet example .直到最近我才注意到我的数据库包含这样的推文: tweet example

I searched for "ozone hole" and it returned a tweet whose text doesn't actually include "ozone hole", but "ozone hole" can be found in the title of the news, to which the author of the tweets made a reference.我搜索了“臭氧洞”,它返回了一条推文,其文本实际上并不包含“臭氧洞”,但可以在新闻标题中找到“臭氧洞”,推文的作者对此进行了引用。

Is there any way to avoid tweets like that and to search for tweets that include my keywords in the actual tweet text?有什么方法可以避免这样的推文并搜索在实际推文文本中包含我的关键字的推文?

Chunk of my code that searches for tweets:我搜索推文的代码块:

for tweet in tweepy.Cursor(api.search,
          q="ozone hole",
          lang="en",
        #Since="2019-11-27",
        #until="2019-11-14",
                       tweet_mode='extended').items():

This is simply how Twitter's search works.这就是 Twitter 搜索的工作原理。 If you search for the same query through Twitter's website, you'll see that it comes up with those same results.如果您通过 Twitter 的网站搜索相同的查询,您会看到它出现了相同的结果。

Note though, that it's likely due to the query showing up in the URL itself, not in the title of that site.但请注意,这可能是由于查询显示在 URL 本身中,而不是该站点的标题中。

Try these commands for the date that you are looking for first:首先针对您要查找的日期尝试这些命令:

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)

Then you can use the command below to specify the keyword然后就可以使用下面的命令来指定关键字

tweets_list = tweepy.Cursor(...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM