如何使用python收集在特定日期发布的有关事件的推文? [英] How to collect tweets about an event that are posted on specific date using python?
本文介绍了如何使用python收集在特定日期发布的有关事件的推文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望收集所有包含特定关键字(例如:manchesterattack、manchester)的推文,这些推文是关于 5 月 22 日发布的曼彻斯特袭击事件.谁能给我一个代码来使用python收集推文我使用了以下代码:
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))
我知道这个代码只返回上周的推文.我想收集5月22日(一个多星期)的推文.我该怎么做?
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?
推荐答案
你说的是web-scrapping
.
有几种方法可以实现这一点:
There are a couple of ways to achieve that:
Twitter API
- 最简单的- 使用
beautifulsoup
、selenium
等抓取工具
Twitter API
- simplest- Use scrapping tools like
beautifulsoup
,selenium
etc.
请做一些相同的研究.干杯.
Please do some research about the same. Cheers.
这篇关于如何使用python收集在特定日期发布的有关事件的推文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文