recaptcha wasnt solving by anticaptcha plugin in selenium python

2024/10/12 8:22:18

I've recently started using selenium for a project I've been working on for a while that involves automation. One of the roadblocks in the plan was the ReCaptcha system, so I decided to use anti-captcha as the service that would solve the captchas when my bot encountered it. I properly installed the plugin and found some test code with selenium on their site.

from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTaskdef captcha_solver():api_key = 'xxxxxxxxxxxxxxxxxxxxxxx'site_key = '6LdZPw8aAAAAAA_1XrIfloCojPwo4TdJ_A_7ioRy'  # grab from siteurl = 'https://www.rp.gob.pa/'client = AnticaptchaClient(api_key)task = NoCaptchaTaskProxylessTask(url, site_key)job = client.createTask(task)job.join()return job.get_solution_response()captcha = captcha_solver()
driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "{}";'.format(captcha))
time.sleep(1)
wait.until(EC.element_to_be_clickable((By.XPATH,'//button[@type="submit"]'))).click()

the anticaptcha says the recaptcha is solved, the solved code comes like this

03AGdBq24C2SwOzrdAoGpltxX-8vMuBEjwSmHVIRkVcthtqHEsmm7sEyac1vUgTZQHs7bUtK0YwW6NiduvAmXQt6xVxGRSvO1XhsiRPTfa8spSxRG6scwInLccriAV408I4plNzEykQVQya9v2u4PMyCyrVQ6NADI_A_56DuQvuzhLKuiNL-eN4MvtwEt1ueDefa3nwHUZoW-hgMiEcg1jQ4UhZJ0Ncz1favKF8aMB--Ru1-ewClN41MjyVwREHn1xuCNtnMt5rxaFLt0f5SehaFkdccem1rbCTqsb7lOomTEWpX0TiWKl2kOP9efgOJDlwV84ISncydrQseda7pTlf6nL0m_oUY8U-tnWFQi2i8g_ZWwOgrXb6o9lBapoy0-z0SWZARHKecBbfwHa906mG_b2jh9-IPOI-6rduxTnDw4HDlizXGKOU7Z8Cb8pQAhiaYEejiaBU0X2Dc44dq7CL4Q_365277zoKG4YDwgRXjUstT39e-3C_-lpjdNHMkkz9RJTNe0kOie2i3U-BruAh3trh-vM8F7JU4f8m52F335q3GdUb8FQXL7Fd9hLJpb9KfDMV0pfmRuxl5NoECKRbP2gtTTXUJ0ZwQ

I execute this solved code to g-recaptcha-response textarea and says the selenium to click the button, but the result is this Result

I cannot solve the recaptcha using anticaptcha, I don't whether my code has a problem, but I followed the official documentation to use the recaptcha. Guys please help me to solve this issue.

Answer

I've finally managed to resolve this myself. In case anyone else is struggling with a similar issue, here was my solution:

  • Open the console and execute the following cmd: ___grecaptcha_cfg.clients
  • Find the path which has the callback function, in my case it's ___grecaptcha_cfg.clients[0].R.R
  • Use the following code: driver.execute_script(f"___grecaptcha_cfg.clients[0].R.R.callback('{new_token}')") (Remember to change the path accordingly)

Can get the path using the google console ___grecaptcha_cfg.clients

Right click the callback -> copy property path and paste in driver.execute_script and add this on start ___grecaptcha_cfg. and pass the solved token value

This Article will help you to find the ___grecaptcha_cfg.clients of your recaptcha site

driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "{}";'.format(g_response))   
time.sleep(1)  
driver.execute_script(f"___grecaptcha_cfg.clients[0].R.R.callback('{g_response}')")
https://en.xdnf.cn/q/69675.html

Related Q&A

Python - check for class existance

Is there a way to check if a class has been defined/exists? I have different options on a menu, and some of them require inherited variables, so if you try to select that function before you have set …

getting a matplotlib colorbar tick outside data limits for use with boundaries keyword

I am trying to use a colorbar to label discrete, coded values plotted using imshow. I can achieve the colorbar that I want using the boundaries and values keywords, which makes the maximum value of the…

Apache Airflow - customize logging format

Is it possible to customize the format that Airflow uses for logging?I tried adding a LOG_FORMAT variable in $AIRFLOW_HOME/airflow.cfg, but it doesnt seem to take effectLOG_FORMAT = "%(asctime)s …

How can I set up Celery to call a custom worker initialization?

I am quite new to Celery and I have been trying to setup a project with 2 separate queues (one to calculate and the other to execute). So far, so good. My problem is that the workers in the execute que…

Why does print(__name__) give builtins?

Im using pycharm.2017.1.2. I installed anaconda2 with py3 environment. in Pycharm, Im using Python3 interpreter, and the code is simply:print(__name__)In Python console in Pycharm, it prints builtins.I…

List Comprehensions and Conditions?

I am trying to see if I can make this code better using list comprehensions. Lets say that I have the following lists:a_list = [HELLO,FOO,FO1BAR,ROOBAR,SHOEBAR]regex_list = [lambda x: re.search(rFOO,…

Python in operator time complexity on range()

I have the following function:def foo(length, num):return num in range(length)Whats the time complexity of this function? Noting that range() creates a Range object on Python 3, will the time complexi…

Pandas read data from a secure FTP server in Python 3

I am looking for a neat solution to read data (using either read_csv or read_sas) to a Pandas Dataframe from a secure FTP server in Python 3. All the examples I can find are many lines and some for Pyt…

How to read XML header in Python

How can I read the header of an XML document in Python 3?Ideally, I would use the defusedxml module as the documentation states that its safer, but at this point (after hours of trying to figure this …

Shift interpolation does not give expected behaviour

When using scipy.ndimage.interpolation.shift to shift a numpy data array along one axis with periodic boundary treatment (mode = wrap), I get an unexpected behavior. The routine tries to force the firs…