Skip to content

Instantly share code, notes, and snippets.

@tribela
Last active November 16, 2016 17:44
Show Gist options
  • Save tribela/b6f089ed5faa1f9647f0 to your computer and use it in GitHub Desktop.
Save tribela/b6f089ed5faa1f9647f0 to your computer and use it in GitHub Desktop.
google recaptcha v2
import time
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.google.com/recaptcha/api2/demo')
captcha_frame = driver.find_element_by_css_selector('iframe[src*="api2/anchor"]')
driver.switch_to_frame(captcha_frame)
driver.find_element_by_css_selector('.recaptcha-checkbox-checkmark').click()
driver.switch_to_default_content()
while 1:
try:
image_frame = driver.find_element_by_css_selector('iframe[src*="api2/frame"]')
except:
time.sleep(1)
continue
else:
break
driver.switch_to_frame(image_frame)
time.sleep(2)
images = driver.find_element_by_css_selector('img.rc-image-tile-33')
buttons = driver.find_elements_by_css_selector('table.rc-imageselect-table-33 td')
verify_button = driver.find_element_by_css_selector('#recaptcha-verify-button')
try:
instructions = driver.find_element_by_css_selector('.rc-imageselect-desc')
except:
instructions = driver.find_element_by_css_selector('.rc-imageselect-desc-no-canonical')
print(images.get_attribute('src'))
print(instructions.text)
inputs = map(lambda x: int(x.strip()) - 1, raw_input().split(','))
for index in inputs:
buttons[index].click()
verify_button.click()
driver.switch_to_default_content()
time.sleep(1)
driver.find_element_by_css_selector('input[type=submit]').click()
time.sleep(5)
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment