简体   繁体   中英

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:

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

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.

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.

In order to fetch older tweets you need to have premium api or sandbox access detail explanation is given in this post

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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