Skip to content

Instantly share code, notes, and snippets.

@ad-m
Created April 7, 2019 23:38
Show Gist options
  • Select an option

  • Save ad-m/3f020544553c09a4063e1aab24c8e9ff to your computer and use it in GitHub Desktop.

Select an option

Save ad-m/3f020544553c09a4063e1aab24c8e9ff to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import time
from os import environ
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask
api_key = environ['KEY']
invisible_captcha = False
url = 'https://www63.bb.com.br/portalbb/djo/id/comprovante/consultaDepositoJudicial.bbx'
client = AnticaptchaClient(api_key)
def get_token(url, site_key, invisible):
task = NoCaptchaTaskProxylessTask(
website_url=url,
website_key=site_key,
is_invisible=invisible
)
job = client.createTask(task)
job.join()
return job.get_solution_response()
def get_driver():
options = Options()
# options.add_argument('-headless')
return Firefox(firefox_options=options)
def process():
driver = get_driver()
driver.get(url)
site_key = get_sitekey(driver)
print("Found site-key", site_key)
token = get_token(url, site_key, invisible_captcha)
print("Found token", site_key)
form_submit(driver, token)
return driver.find_element_by_class_name('alert-danger').text
def form_submit(driver, token):
driver.execute_script("document.getElementById('g-recaptcha-response').innerHTML='{}';".format(token))
time.sleep(1)
driver.find_element_by_id('formulario:btnContinuar').click()
time.sleep(1)
def get_sitekey(driver):
return driver. \
find_element_by_class_name('g-recaptcha'). \
get_attribute('data-sitekey')
if __name__ == '__main__':
result = process()
assert 'reCaptcha' not in result
assert 'Campo obrigatório não preenchido.' in process()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment