使用python,如何在两个日期之间使用收集推文(使用tweepy)? [英] Using python, how to use collect tweets (using tweepy) between two dates?
问题描述
我如何使用 python 和 tweepy 来收集两个给定日期之间的 Twitter 推文?
有没有办法将 from...until... 值传递给搜索 api?
笔记:我需要能够返回搜索但不限于特定用户
我正在使用 python,我知道代码应该是这样的,但我需要帮助才能使它工作.
<前>auth = tweepy.OAuthHandler(consumer_key,consumer_secret)auth.set_access_token(access_token_key, access_token_secret)api = tweepy.API(auth)集合 = []对于 tweepy.Cursor(api.search, ???????).items() 中的推文:集合[tweet.id] = tweet._json经过长时间的调查和稳定后,我很乐意分享我的发现.
按地理编码搜索:以这种格式在 'q' 参数中传递地理编码参数:geocode:"37.781157,-122.398720,500mi",双引号很重要.请注意,此 API 不再支持 near 参数.地理编码提供了更大的灵活性
按时间线搜索:使用参数since"和until",格式如下:since:2016-08-01 until:2016-08-02"
还有一个更重要的注意事项... Twitter 不允许查询日期太旧.我不确定,但我认为他们只给 10-14 天.所以你不能通过这种方式查询上个月的推文.
====================================
tweepy.Cursor(api.search,q='geocode:"37.781157,-122.398720,1mi" 自:2016-08-01 至:2016-08-02 包括:转发',结果类型='最近',include_entities=真,monitor_rate_limit=假,wait_on_rate_limit=False).items(300):tweet_id = status.idtweet_json = status._json
How can i use python and tweepy in order to collect tweets from twitter that are between two given dates?
is there a way to pass from...until... values to the search api?
Note:
I need to be able to search back but WITHOUT limitation to a specific user
i am using python and I know that the code should be something like this but i need help to make it work.
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token_key, access_token_secret) api = tweepy.API(auth) collection = [] for tweet in tweepy.Cursor(api.search, ???????).items(): collection[tweet.id] = tweet._json
After long hours of investigations and stabilization i can gladly share my findings.
search by geocode: pass the geocode parameter in the 'q' parameter in this format: geocode:"37.781157,-122.398720,500mi" , the double quotes are important. notice that the parameter near is not supported anymore by this api. The geocode gives more flexibility
search by timeline: use the parameters "since" and "until" in the following format: "since:2016-08-01 until:2016-08-02"
there is one more important note... twitter don't allow queries with too old dates. I am not sure but i think they give only 10-14 days back. So you cannot query this way for tweets of last month.
===================================
for status in tweepy.Cursor(api.search,
q='geocode:"37.781157,-122.398720,1mi" since:2016-08-01 until:2016-08-02 include:retweets',
result_type='recent',
include_entities=True,
monitor_rate_limit=False,
wait_on_rate_limit=False).items(300):
tweet_id = status.id
tweet_json = status._json
这篇关于使用python,如何在两个日期之间使用收集推文(使用tweepy)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!