Python Twython将提取推文

Python Twython将提取推文,python,twitter,twython,Python,Twitter,Twython,我正在使用twythontwitterapi来提取tweets。但我只收到100条推特。我想摘录2013年12月10日至2014年3月10日的推文。我在搜索函数中提到了count=1000 利率上限是100我明白了。有没有一种方法可以在给定的时间段内无速率限制地获取这些推文 from twython import Twython import csv from dateutil import parser from dateutil.parser import parse as pars

我正在使用twythontwitterapi来提取tweets。但我只收到100条推特。我想摘录2013年12月10日至2014年3月10日的推文。我在搜索函数中提到了count=1000

利率上限是100我明白了。有没有一种方法可以在给定的时间段内无速率限制地获取这些推文

 from twython import Twython
 import csv
 from dateutil import parser
 from dateutil.parser import parse as parse_date
 import datetime
 from datetime import datetime
 import pytz

 utc=pytz.UTC

 APP_KEY = 'xxxxxxxxxxx'    
 APP_SECRET = 'xxxxxxxxxxx'
 OAUTH_TOKEN = 'xxxxxxxx'  # Access Token here
 OAUTH_TOKEN_SECRET = 'xxxxxxxxxxx'  

 t = Twython(app_key=APP_KEY, app_secret=APP_SECRET, oauth_token=OAUTH_TOKEN,      oauth_token_secret=OAUTH_TOKEN_SECRET)

 search=t.search(q='AAPL', count="1000",since='2013-12-10')
 tweets= search['statuses']


 for tweet in tweets:
     do something

通过
搜索API
访问推文时有一个限制。看看这个

搜索API
通常只提供过去一周的推文


当您试图检索过去3/4个月的推文时,您不会得到旧的推文。

通过
搜索API访问推文时有一个限制。看看这个

搜索API
通常只提供过去一周的推文


当您试图检索过去3/4个月的推文时,您不会得到旧的推文。

对于Twython,搜索API是有限的,但我仅使用get_user_timeline就成功了

我解决了一个类似的问题,我想从一个用户那里获取最后X条推文

如果你阅读了文档,对我有效的技巧是跟踪我读过的最后一条tweet的id,并使用max_id一直读到我下一次请求时的那条tweet

对于您的情况,您只需要修改while循环以在“created_at”的某些条件下停止。类似这样的方法可能会奏效:

# Grab the first 200 tweets
last_id = 0
full_timeline = 200
result = t.get_user_timeline(screen_name='NAME', count = full_timeline)

for tweet in result:
    print(tweet['text'], tweet['created_at'])
    last_id = tweet['id']

# Update full timeline to see how many tweets were actually received
# Full timeline will be less than 200 if we read all the users tweets
full_timeline = len(result)

# 199 cause result[1:] is used to trim duplicated results cause of max_id
while full_timeline >= 199:
    result = t.get_user_timeline(screen_name='NAME', count = 200, max_id = last_id)

    # Since max_id is inclusive with its bound, it will repeat the same tweet we last read, so trim out that tweet
    result = result[1:]
    for tweet in result:
        print(tweet['text'], tweet['created_at'])
        last_id = tweet['id']

    # Update full_timeline to keep loop going if there are leftover teweets
    full_timeline = len(result)

对于Twython,搜索API是有限的,但我仅使用get_user_timeline就取得了成功

我解决了一个类似的问题,我想从一个用户那里获取最后X条推文

如果你阅读了文档,对我有效的技巧是跟踪我读过的最后一条tweet的id,并使用max_id一直读到我下一次请求时的那条tweet

对于您的情况,您只需要修改while循环以在“created_at”的某些条件下停止。类似这样的方法可能会奏效:

# Grab the first 200 tweets
last_id = 0
full_timeline = 200
result = t.get_user_timeline(screen_name='NAME', count = full_timeline)

for tweet in result:
    print(tweet['text'], tweet['created_at'])
    last_id = tweet['id']

# Update full timeline to see how many tweets were actually received
# Full timeline will be less than 200 if we read all the users tweets
full_timeline = len(result)

# 199 cause result[1:] is used to trim duplicated results cause of max_id
while full_timeline >= 199:
    result = t.get_user_timeline(screen_name='NAME', count = 200, max_id = last_id)

    # Since max_id is inclusive with its bound, it will repeat the same tweet we last read, so trim out that tweet
    result = result[1:]
    for tweet in result:
        print(tweet['text'], tweet['created_at'])
        last_id = tweet['id']

    # Update full_timeline to keep loop going if there are leftover teweets
    full_timeline = len(result)

还有别的出路吗?有别的出路吗?