问题
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:
What you are talking about is web-scrapping
.
There are a couple of ways to achieve that:
- Twitter API - simplest
- Use scrapping tools like
beautifulsoup
,selenium
etc.
Please do some research about the same. Cheers.
来源:https://stackoverflow.com/questions/44303555/how-to-collect-tweets-about-an-event-that-are-posted-on-specific-date-using-pyth