Friday 18 August 2023

Unable to find data-sitekey attribute in hCAPTCHA on Indeed Selenium Automation

I am trying to login to Indeed.com using Selenium 4.10.0 using Python 3.10.1. When I do so, I get an hCAPTCHA that I am attempting to solve with the 2captcha API. However, I am unable to find the correct data-sitekey attribute for the website. As a result, I keep getting an ERROR_WRONG_GOOGLEKEY error from the 2captcha API.

To attempt to search for the Indeed sitekey, I used Google Chrome's DevTools. While unable to find an exact data-sitekey attribute, I am able to find a sitekey parameter inside the source of the <iframe> containing the CAPTCHA. Attached are images of my DevTools windows, the <iframe> tag showing where the sitekey is mentioned, and the code I am using to solve the CAPTCHA.

By inspecting the <iframe>, I found a sitekey of 7734ec9b-f8cb-44b2-9fac-3a502cb4f1bf for Indeed. Is this the correct sitekey?

Edit 8/17/2023: From talking to 2Captcha's support, it seems that the sitekey is hidden inside a callback function. Do you have any insight into how to look for the sitekey by inspecting the JavaScript on the page? Thank you.

<iframe src="https://newassets.hcaptcha.com/captcha/v1/c29d40e/static/hcaptcha.html#frame=checkbox&amp;id=0ffwhp2wwjif&amp;host=secure.indeed.com&amp;sentry=true&amp;reportapi=https%3A%2F%2Faccounts.hcaptcha.com&amp;recaptchacompat=true&amp;custom=false&amp;hl=en&amp;tplinks=on&amp;pstissuer=https%3A%2F%2Fpst-issuer.hcaptcha.com&amp;sitekey=7734ec9b-f8cb-44b2-9fac-3a502cb4f1bf&amp;theme=light&amp;origin=https%3A%2F%2Fsecure.indeed.com" 
tabindex="0" 
frameborder="0" 
scrolling="no" 
allow="private-state-token-issuance 'src'; 
private-state-token-redemption 'src'" 
title="Widget containing checkbox for hCaptcha security challenge" 
data-hcaptcha-widget-id="0ffwhp2wwjif" 
data-hcaptcha-response="" 
style="width: 303px; height: 78px; overflow: hidden;">

</iframe>
def solve_captcha(driver, site_key, page_url):
    #We solve the captcha here.
    MY_API_KEY = '<MY_API_KEY>'
    solver = TwoCaptcha(MY_API_KEY)
    response = solver.recaptcha(sitekey=site_key, url=page_url)
    code = response['code']

    #We send the solution here.
    try:
        captcha_element = driver.find_element(By.XPATH, 
                                          "//*[contains(@id,'g-captcha-response')]")
        driver.execute_script(f'arguments[0].value = "{code}";', captcha_element)
        print('Solved CAPTCHA')
    except:
        print('There is no CAPTCHA to solve.')

Image of DevTools window showing sitekey attribute of CAPTCHA on Indeed.com login page.



from Unable to find data-sitekey attribute in hCAPTCHA on Indeed Selenium Automation

No comments:

Post a Comment