From 59967225b59e268d787fa641cad6e2c50dcc5848 Mon Sep 17 00:00:00 2001 From: Salastil Date: Thu, 13 Mar 2025 16:09:39 -0400 Subject: [PATCH] Changed login order to accommodate 2fa, added prompt, change language on ratelimit waiting --- scraper/progress.py | 2 +- scraper/twitter_scraper.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scraper/progress.py b/scraper/progress.py index 49e4f69..0900c4d 100644 --- a/scraper/progress.py +++ b/scraper/progress.py @@ -20,7 +20,7 @@ class Progress: if no_tweets_limit: if waiting: sys.stdout.write( - "\rTweets scraped : {} - waiting to access older tweets {} min on 15 min".format( + "\rTweets scraped : {} - Rate Limited: waiting to access older tweets. Attempt to proceed {} over 15 min".format( current, retry_cnt ) ) diff --git a/scraper/twitter_scraper.py b/scraper/twitter_scraper.py index 6595bc4..5f02191 100644 --- a/scraper/twitter_scraper.py +++ b/scraper/twitter_scraper.py @@ -212,8 +212,8 @@ class Twitter_Scraper: sleep(3) self._input_username() - self._input_unusual_activity() self._input_password() + self._input_unusual_activity() cookies = self.driver.get_cookies() @@ -282,15 +282,17 @@ It may be due to the following: try: unusual_activity = self.driver.find_element( "xpath", "//input[@data-testid='ocfEnterTextTextInput']" - ) - unusual_activity.send_keys(self.username) + ) + # Prompt for 2FA code input + two_fa_code = input("Enter 2FA code: ").strip() + unusual_activity.send_keys(two_fa_code) unusual_activity.send_keys(Keys.RETURN) sleep(3) break except NoSuchElementException: input_attempt += 1 if input_attempt >= 3: - break + break def _input_password(self): input_attempt = 0