|
| 1 | +# Date of last verification: June 28, 2019 |
| 2 | +import re |
| 3 | +from os import environ |
| 4 | + |
| 5 | +from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask |
| 6 | + |
| 7 | +api_key = environ['KEY'] |
| 8 | +invisible_captcha = True |
| 9 | +url = 'https://www.swagbucks.com/p/login' |
| 10 | +client = AnticaptchaClient(api_key) |
| 11 | + |
| 12 | + |
| 13 | +def get_token(website_url, site_key, invisible): |
| 14 | + task = NoCaptchaTaskProxylessTask( |
| 15 | + website_url=website_url, |
| 16 | + website_key=site_key, |
| 17 | + is_invisible=invisible |
| 18 | + ) |
| 19 | + job = client.createTask(task) |
| 20 | + job.join() |
| 21 | + return job.get_solution_response() |
| 22 | + |
| 23 | + |
| 24 | +def process(driver): |
| 25 | + driver.get(url) |
| 26 | + site_key = re.search("captchaSitekey = '(.+?)'",driver.page_source).group(1) |
| 27 | + print("Found site-key", site_key) |
| 28 | + print("Send challenge") |
| 29 | + token = get_token(driver.current_url, site_key, invisible_captcha) |
| 30 | + print("Received challenge-response") |
| 31 | + driver. find_element_by_xpath( '//*[@id="sbxJxRegEmail"]'). send_keys( '[email protected]') |
| 32 | + driver.find_element_by_xpath('//*[@id="sbxJxRegPswd"]').send_keys('password') |
| 33 | + driver.find_element_by_xpath('//*[@id="loginBtn"]').click() |
| 34 | + print("Form submitted") |
| 35 | + driver.execute_script("document.getElementById('g-recaptcha-response').innerHTML='{}';".format(token)) |
| 36 | + driver.execute_script("document.getElementById('loginForm').submit()") |
| 37 | + return driver.find_element_by_xpath('//*[@id="divErLandingPage"]').text |
| 38 | + |
| 39 | + |
| 40 | +if __name__ == '__main__': |
| 41 | + from selenium.webdriver import Firefox |
| 42 | + from selenium.webdriver.firefox.options import Options |
| 43 | + |
| 44 | + options = Options() |
| 45 | + # options.add_argument('-headless') |
| 46 | + driver = Firefox(firefox_options=options) |
| 47 | + assert 'Incorrect Email/Password Combination' in process(driver) |
0 commit comments