I built a Python framework for testing, stealth, and CAPTCHA-bypass

Regular Selenium didn’t have all the features I needed (like testing and stealth), so I built a framework around it.

GitHub: https://github.com/seleniumbase/SeleniumBase

I added two different stealth modes along the way:

UC Mode – (which works by modifying Chromedriver) – First released in 2022. CDP Mode – (which works by using the CDP API) – First released in 2024.

The testing components have been around for much longer than that, as the framework integrates with pytest as a plugin. (Most examples in the SeleniumBase/examples/ folder still run with pytest, although many of the newer examples for stealth run with raw python.)

Both async and non-async formats are supported. (See the full list)

A few stealth examples:

1: Google Search – (Avoids reCAPTCHA) – Uses regular UC Mode.

from seleniumbase import SB with SB(test=True, uc=True) as sb: sb.open(« https://google.com/ncr ») sb.type(‘[title= »Search »]’, « SeleniumBase GitHub pagen ») sb.click(‘[href*= »github.com/seleniumbase/ »]’) sb.save_screenshot_to_logs() # ./latest_logs/ print(sb.get_page_title())

2: Indeed Search – (Avoids Cloudflare) – Uses CDP Mode from UC Mode.

from seleniumbase import SB with SB(uc=True, test=True) as sb: url = « https://www.indeed.com/companies/search » sb.activate_cdp_mode(url) sb.sleep(1) sb.uc_gui_click_captcha() sb.sleep(2) company = « NASA Jet Propulsion Laboratory » sb.press_keys(‘input[data-testid= »company-search-box »]’, company) sb.click(‘button[type= »submit »]’) sb.click(‘a:contains(« %s »)’ % company) sb.sleep(2) print(sb.get_text(‘[data-testid= »AboutSection-section »]’))

3: Glassdoor – (Avoids Cloudflare) – Uses CDP Mode from UC Mode.

from seleniumbase import SB with SB(uc=True, test=True) as sb: url = « https://www.glassdoor.com/Reviews/index.htm » sb.activate_cdp_mode(url) sb.sleep(1) sb.uc_gui_click_captcha() sb.sleep(2)

More examples can be found from the GitHub page. (Stars are welcome! ⭐)

There’s also a pure CDP stealth format that doesn’t use Selenium at all (by going directly through the CDP API). Example of that.

submitted by /u/SeleniumBase to r/Python
[link] [comments]


Commentaires

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *