How to collect tweets about an event that are post

2019-09-23 05:35发布

I wish to collect all tweets containing specific keywords(ex:manchesterattack,manchester) that are posted about the manchester attack from 22may. Can anyone provide me a code to collect tweets using python I have used following code:

import json
import tweepy
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True,  wait_on_rate_limit_notify=True)

for tweet in tweepy.Cursor(api.search, q="manchester OR manchesterarena OR    manchesterbombing  ", lang="en").items():
    print(json.dumps(tweet._json))

I know this code return tweets from last week only. I would like to collect tweets from 22may(more than a week). How can I do that?

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-23 06:16

What you are talking about is web-scrapping.

There are a couple of ways to achieve that:

  1. Twitter API - simplest
  2. Use scrapping tools like beautifulsoup, selenium etc.

Please do some research about the same. Cheers.

查看更多
登录 后发表回答