Skip to content

Instantly share code, notes, and snippets.

@theshahzaibc
Created January 7, 2021 17:04
Show Gist options
  • Save theshahzaibc/78e4ac3766910ffe395c0ef2bff31878 to your computer and use it in GitHub Desktop.
Save theshahzaibc/78e4ac3766910ffe395c0ef2bff31878 to your computer and use it in GitHub Desktop.
if audioBtnFound:
# if audio button found then procced
delay()
try:
while True:
# get the mp3 audio file
src = driver.find_element_by_id("audio-source").get_attribute("src")
print("[INFO] Audio src: %s" % src)
# download the mp3 audio file from the source
urllib.request.urlretrieve(src, os.getcwd() + audioFile)
# Speech To Text Conversion
key = audioToText(os.getcwd() + audioFile)
print("[INFO] Recaptcha Key: %s" % key)
delay()
driver.switch_to.default_content()
iframe = driver.find_elements_by_tag_name('iframe')[audioBtnIndex]
delay()
driver.switch_to.frame(iframe)
# key in results and submit
# input field where we have to write the audio text
# delay()
inputField = driver.find_element_by_id("audio-response")
inputField2 = driver.find_element_by_id("audio-response")
ActionChains(driver).move_to_element(inputField).pause(1).click(inputField).perform()
time.sleep(1)
for k in key:
inputField2.send_keys(k)
time.sleep(0.5)
delay()
ActionChains(driver).move_to_element(inputField2).pause(1).send_keys(Keys.ENTER).perform()
delay()
if isBlocked():
sys.exit("Caught/Blocked by Google")
# check if verification failed or passed?
err = driver.find_elements_by_class_name('rc-audiochallenge-error-message')[0]
if err.text == "" or err.value_of_css_property('display') == 'none':
print("[INFO] Success!")
break
# if failed while loop run again and again untill success!
except Exception as e:
print(e)
sys.exit("[INFO] Possibly blocked by google. Change IP,Use Proxy method for requests")
else:
sys.exit("[INFO] Audio Play Button not found! In Very rare cases!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment