简体   繁体   English

存储在特定日期范围内发布的所有推文(Tweepy,Python)

[英]Store all tweets tweeted during certain date range (Tweepy, Python)

I am trying to retrieve all of the tweets matching a query between a start date and an end date.我正在尝试检索与开始日期和结束日期之间的查询匹配的所有推文。 I am using the following code to store the tweets in a csv file:我正在使用以下代码将推文存储在 csv 文件中:

for tweet in tweepy.Cursor(api.search, q=searchQuery, count=100, lang="en", since="2019-12-01", until="2020-04-07").items():
       print(tweet.created_at, tweet.text)
       csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8')])
       tweetCountTest += 1
       print(tweetCountTest)

It works fine if I set the end (until) date after 2020-05-05, but just exits the loop when I put any date before that.如果我在 2020-05-05 之后设置结束(直到)日期,它工作正常,但是当我在此之前放置任何日期时,它只会退出循环。 Is there something wrong with my code?我的代码有问题吗? Ideally, I want to be able to store all the tweets matching my query tweeted in any date range.理想情况下,我希望能够存储与我的查询在任何日期范围内发布的所有推文。 Today is 2020-05-12今天是2020-05-12

There are so many solutions already posted in stackoverflow for the same topic, you could have done some research to get your answer before posting. stackoverflow 中已经针对同一主题发布了很多解决方案,您可以在发布之前进行一些研究以获得答案。

Standard search only can fetch last 7 days of tweets, that's why when you give until to latest, you are able to fetch the tweets.标准搜索只能获取最近 7 天的推文,这就是为什么当您提供直到最新的推文时,您可以获取推文。

In order to fetch older tweets you need to have premium api or sandbox access detail explanation is given in this post为了获取较旧的推文,您需要拥有高级 api 或沙盒访问详细说明在这篇文章中给出

https://stackoverflow.com/a/61737450/10703097 https://stackoverflow.com/a/61737450/10703097

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

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