1

Ok first of all I don't want to annoy anyone here I'm fairly new to coding and I'm well aware that asking in these forums should be your last place to go and only after you googled for a while. Anyway I have a problem. I tried to use 2captcha for my python web scraping automation. When I run the script I get the captcha token from 2captcha and in their API documentation they said, that I have to put the Token into the Value of the Element with fc-token inside (Screenshot)

Screen Shot of the API instruction of 2 captcha

Now I would like to place the token into the value="" of the html code and then submit.

This is what I've tried so far:

    ## Gets the captcha Token
time.sleep(15)
url=str(web.current_url)
solver = TwoCaptcha(APIKEY)

try:
    result = solver.funcaptcha(sitekey='B7D8911C-5CC8-A9A3-35B0-554ACEE604DA',
                               url=url,
                               surl='https://client-api.arkoselabs.com')
except Exception as e:
    sys.exit(e)

print(result['code'])
## The Captcha Token
token= result['code']

time.sleep(10)

##Switching to the right Iframe 
web.switch_to.frame('enforcementFrame')

##Here Im trying to change the value of the Element "FunCaptcha-Token" with JS
web.execute_script('''
  let {token} = arguments
  document.querySelector('FunCaptcha-Token').value = token
''', token)

Now when I run the script I get the token so the 2captcha part should work but the JS in Python part doesn't work. Thats the error code I get:

KeyError: 'document.getElementById("FunCaptcha-Token").value=87260ba9ceb681253.3489941501|r=us-ea [...] continues with the token

Now I'll add the HTML code.

<input type="hidden" id="FunCaptcha-Token" name="fc-token" value="91560ba8aabd2a839.9381249805|r=eu-west-1|metabgclr=%23ffffff|maintxtclr=%231B1B1B|mainbgclr=%23ffffff|guitextcolor=%23747474|metaiconclr=%23757575|meta=7|lang=de|pk=B7D8911C-5CC8-A9A3-35B0-554ACEE604DA|at=40|ht=1|atp=2|cdn_url=https%3A%2F%2Fclient-api.arkoselabs.com%2Fcdn%2Ffc|lurl=https%3A%2F%2Faudio-eu-west-1.arkoselabs.com|surl=https%3A%2F%2Fclient-api.arkoselabs.com">

HTML Code with the element selected

Sorry for my long post I thank you in advance.

1 Answer 1

2

It should look like:

driver.execute_script('''
  let {token} = arguments
  document.querySelector('#FunCaptcha-Token').value = token
''', token)

Then you want to submit the form or run the callback

Sign up to request clarification or add additional context in comments.

12 Comments

Hey thank you very much for your Answer unfortunately I can't get it to work I get this error message: selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot set property 'value' of null
That means it's not there. Maybe it's in a iframe?
Hey thanks for your quick response I actualized the code I still get the same error message.
We need to see the url, sorry.
well that's rather difficult bc its during the sign up process of outlook.live.com
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.