-1

ハッシュタグ #nationaldoughnutday のすべてのツイートをクロールしようとしていますが、レート制限のために失敗しています。

以下のコードを参考に、レート制限がリセットされたときに、最後にクロールした日付 (until_date) からスクレイピングを再開できるように、コードを while ループに入れてみました。

ただし、このエラーが繰り返し発生し続け、長時間スリープした後、クローラーがクロールを再開していないようです。

TweepError Failed to send request: ('Connection aborted.', error (10054, 'An existing connection was forcibly closed by the remote host'))
Sleeping...
TweepError Failed to send request: ('Connection aborted.', error (10054, 'An existing connection was forcibly closed by the remote host'))
Sleeping...
TweepError Failed to send request: ('Connection aborted.', error (10054, 'An existing connection was forcibly closed by the remote host'))

内部のtry catchループを削除しようとしましたが、役に立ちませんでした

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)
query = '#nationaldoughnutday'
untill_date = '01-07-2019'

while True:
    try: #outer try catch 
        tweets = tweepy.Cursor(api.search, q=query + '-filter:retweets', rpp=100, lang='en',tweet_mode='extended',until = until_date).items()
        for tweet in tweets:
            try: #inner try catch 
                print "tweet : ", tweet.created_at
                #this is so that if i reconnect with cursor, i will start with the date before the last crawled tweet
                until_date = tweet.created_at.date() - datetime.timedelta(days=1)
                
            except tweepy.TweepError as e:
                print 'Inner TweepyError', e
                time.sleep(17 * 60)
                break
    except tweepy.TweepError as e:
        print 'Inner TweepyError',
        print "sleeping ...."
        time.sleep(17 * 60)
        continue
    except StopIteration:
                break

前もって感謝します!

4

1 に答える 1