How to collect tweets about an event that are posted on specific date using python?

此生再无相见时 提交于 2019-12-25 18:53:40

问题


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:

  1. Twitter API - simplest
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!