2

I have the following script in Python but when the page loads the captcha does not work

Can someone help me?

On Windows I have this code that works well for me but on Linux it doesn't work for me

import json
from seleniumbase import SB

with SB(uc=True, test=True, ad_block=True) as sb:
    url = "https://www.nombrerutyfirma.com/"
    sb.activate_cdp_mode(url)
    sb.sleep(2)
    cf_shadow = '[style="display: grid;"] div div'
    if sb.is_element_visible(cf_shadow):
        sb.cdp.gui_click_element(cf_shadow)
    sb.sleep(2)

    sb.open(url)
    sb.wait_for_element('body', timeout=15)
    sb.click('a[href="#rut"]')
    rut_input = sb.wait_for_element_visible('div#rut input[name="term"]', timeout=10)
    rut_input.send_keys("21.405.338-1") 
    rut_input.send_keys("\ue007")
    rows = sb.wait_for_elements('table.table-hover tbody tr', timeout=10)
    data = []
    for row in rows:
        columns = row.find_elements('td')
        record = {
            "Nombre": columns[0].text,
            "RUT": columns[1].text,
            "Sexo": columns[2].text,
            "Dirección": columns[3].text,
            "Ciudad/Comuna": columns[4].text,
        }
        data.append(record)

    json_data = json.dumps(data, ensure_ascii=False, indent=4)
    print(json_data)

How do I take it to seleniumbase and be able to obtain the data. I need help please.

When running the script with "xvfb-run python3 py3.py" it returns this error, This error is because the captcha has not been processed, so the RUT label does not exist

    Haciendo clic en el tab de 'RUT'...
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/dist-packages/seleniumbase/plugins/sb_manager.py", line 1223, in SB
    yield sb
  File "/home/scripts_python/py3.py", line 25, in <module>
    sb.click('a[href="#rut"]')
  File "/usr/local/lib/python3.12/dist-packages/seleniumbase/fixtures/base_case.py", line 395, in click
    self.cdp.click(selector, timeout=timeout)
  File "/usr/local/lib/python3.12/dist-packages/seleniumbase/core/sb_cdp.py", line 633, in click
    element = self.find_element(selector, timeout=timeout)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/seleniumbase/core/sb_cdp.py", line 165, in find_element
    raise Exception(message)
Exception: 
 Element {a[href="#rut"]} was not found after 7 seconds!

1 Answer 1

1

SeleniumBase now has CDP Mode, a subset of UC Mode that is especially stealthy on Linux. There are some special methods for clicking on CAPTCHAs. Here's the script that'll work on Mac, Windows, and Linux:

from seleniumbase import SB

with SB(uc=True, test=True, ad_block=True) as sb:
    url = "https://www.nombrerutyfirma.com/"
    sb.activate_cdp_mode(url)
    sb.sleep(2)
    cf_shadow = '[style="display: grid;"] div div'
    if sb.is_element_visible(cf_shadow):
        sb.cdp.gui_click_element(cf_shadow)
    sb.sleep(2)

It'll even work on GitHub Actions, as shown in this SeleniumBase tutorial: https://www.youtube.com/watch?v=gEZhTfaIxHQ

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

10 Comments

I tried the code that you shared with me but it doesn't work, it still doesn't pass the captcha.
I tried it on Windows if it works but on Linux it doesn't work.
What kind of Linux? It works in GitHub Actions.
I tried it on Linux aws ubuntu
How can we add the other things to the code that I passed to you to see if the captcha is really being passed?
|

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.