-
Notifications
You must be signed in to change notification settings - Fork 74
DEFEAT RECAPTCHA #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
DEFEAT RECAPTCHA #26
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| CAPTCHA_BOX = 'recapBorderAccessible' | ||
| AUDIO_ERROR_MESSAGE = 'rc-audiochallenge-error-message' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| CAPTCHA_MP3_FILENAME = '1.mp3' | ||
| CAPTCHA_WAV_FILENAME = '2.wav' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| IFRAME = 'iframe' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,19 +4,28 @@ | |
| import sys | ||
| import time | ||
|
|
||
| import requests | ||
| import speech_recognition as sr | ||
| from faker import Faker | ||
| from pydub import AudioSegment | ||
| from selenium import webdriver | ||
| from selenium.webdriver.common.keys import Keys | ||
| from selenium.webdriver.support.ui import Select | ||
|
|
||
| from constants.classNames import * | ||
| from constants.common import * | ||
| from constants.elementIds import * | ||
| from constants.email import * | ||
| from constants.filenames import * | ||
| from constants.location import * | ||
| from constants.tagNames import * | ||
| from constants.urls import * | ||
| from constants.xPaths import * | ||
|
|
||
| fake = Faker() | ||
| chromedriver_location = CHROMEDRIVER_PATH | ||
| filename = CAPTCHA_MP3_FILENAME | ||
| speech_recognition_recognizer = sr.Recognizer() | ||
| # Change default in module for print to flush | ||
| # https://stackoverflow.com/questions/230751/how-can-i-flush-the-output-of-the-print-function-unbuffer-python-output#:~:text=Changing%20the%20default%20in%20one%20module%20to%20flush%3DTrue | ||
| print = functools.partial(print, flush=True) | ||
|
|
@@ -66,6 +75,58 @@ def generate_account(driver): | |
| time.sleep(1.5) | ||
| driver.find_element_by_xpath(ACCEPT_BUTTON).click() | ||
| time.sleep(2) | ||
| googleClass = driver.find_elements_by_class_name(CAPTCHA_BOX)[0] | ||
| time.sleep(2) | ||
| outerIFrame = googleClass.find_element_by_tag_name(IFRAME) | ||
| time.sleep(1) | ||
| outerIFrame.click() | ||
| time.sleep(2) | ||
| allIframesLen = len(driver.find_elements_by_tag_name(IFRAME)) | ||
| time.sleep(1) | ||
| audioBtnFound = False | ||
| audioBtnIndex = -1 | ||
| for i in range(allIframesLen): | ||
| driver.switch_to.default_content() | ||
| iframe = driver.find_elements_by_tag_name(IFRAME)[i] | ||
| driver.switch_to.frame(iframe) | ||
| driver.implicitly_wait(2) | ||
| try: | ||
| print(f'TRYING {i + 1} of {allIframesLen} ...') | ||
| audioBtn = driver.find_element_by_id(RECAPTCHA_AUDIO_BUTTON) or driver.find_element_by_id(RECAPTCHA_ANCHOR) | ||
| audioBtn.click() | ||
| audioBtnFound = True | ||
| audioBtnIndex = i | ||
| break | ||
| except Exception as e: | ||
| print(f'TRY {i + 1} of {allIframesLen} FAILED: {e}') | ||
| pass | ||
| if audioBtnFound: | ||
| try: | ||
| while True: | ||
| href = driver.find_element_by_id(AUDIO_SOURCE).get_attribute('src') | ||
| response = requests.get(href, stream=True) | ||
| saveFile(response, filename) | ||
| response = audioToText(filename) | ||
| print(f'TRYING "{response}" TO SOLVE RECAPTCHA...') | ||
| driver.switch_to.default_content() | ||
| iframe = driver.find_elements_by_tag_name(IFRAME)[audioBtnIndex] | ||
| driver.switch_to.frame(iframe) | ||
| inputButton = driver.find_element_by_id(AUDIO_RESPONSE) | ||
| inputButton.send_keys(response) | ||
| inputButton.send_keys(Keys.ENTER) | ||
| time.sleep(2) | ||
| errorMsg = driver.find_elements_by_class_name(AUDIO_ERROR_MESSAGE)[0] | ||
| if errorMsg.text == "" or errorMsg.value_of_css_property('display') == 'none': | ||
| print("RECAPTCHA DEFEATED") | ||
| break | ||
| except Exception as e: | ||
| print(e) | ||
| print( | ||
| 'Oops, something happened. Check above this message for errors or check the chrome window to see if captcha locked you out...') | ||
| else: | ||
| print('Button not found. This should not happen.') | ||
| time.sleep(2) | ||
| driver.switch_to.default_content() | ||
| driver.find_element_by_xpath(CREATE_ACCOUNT_BUTTON).click() | ||
| time.sleep(1.5) | ||
|
|
||
|
|
@@ -132,6 +193,7 @@ def fill_out_application_and_submit(driver, random_city): | |
| time.sleep(5) | ||
| driver.find_element_by_xpath(APPLY_BUTTON).click() | ||
| print(f"successfully submitted application") | ||
| time.sleep(5) | ||
|
|
||
|
|
||
| def random_email(name=None): | ||
|
|
@@ -155,6 +217,28 @@ def random_email(name=None): | |
| random.choices(EMAIL_DATA, emailChoices)[0][1] | ||
|
|
||
|
|
||
| def audioToText(mp3Path): | ||
| # convert wav to mp3 | ||
| sound = AudioSegment.from_mp3(mp3Path) | ||
| sound.export(CAPTCHA_WAV_FILENAME, format="wav") | ||
|
|
||
| with sr.AudioFile(CAPTCHA_WAV_FILENAME) as source: | ||
| audio_text = speech_recognition_recognizer.listen(source) | ||
| try: | ||
| text = speech_recognition_recognizer.recognize_google(audio_text) | ||
| print('Converting audio transcripts into text ...') | ||
| return text | ||
| except Exception as e: | ||
| print(e) | ||
| print('Sorry.. run again...') | ||
|
|
||
|
|
||
| def saveFile(content, filename): | ||
| with open(filename, "wb") as handle: | ||
| for data in content.iter_content(): | ||
| handle.write(data) | ||
|
|
||
|
|
||
| def main(): | ||
| while True: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If desired, the multiprocessing implementation from #21 could be placed here. |
||
| random_city = random.choice(list(CITIES_TO_URLS.keys())) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm almost wondering if a different function should be implemented for handling captchas outside of generate_account. Maybe the same code in a handle_captcha function with param driver? It's nitpicky, and the PR should still be accepted if the change isn't implemented, but I think readability could improve a bit.