Skip to content

Commit 70be9b0

Browse files
committed
Update examples
1 parent c4d2d1a commit 70be9b0

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

examples/cdp_mode/ReadMe.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66

77
--------
88

9-
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM"><img src="https://github.com/user-attachments/assets/91e7ff7b-d155-4ba9-b17b-b097825fcf42" title="SeleniumBase on YouTube" width="350" /></a>
9+
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM"><img src="https://github.com/user-attachments/assets/91e7ff7b-d155-4ba9-b17b-b097825fcf42" title="SeleniumBase on YouTube" width="320" /></a>
1010
<p>(<b><a href="https://www.youtube.com/watch?v=Mr90iQmNsKM">Watch the CDP Mode tutorial on YouTube! ▶️</a></b>)</p>
1111

1212
--------
1313

14-
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=vt2zsdiNh3U"><img src="https://github.com/user-attachments/assets/82ab2715-727e-4d09-9314-b8905795dc43" title="SeleniumBase on YouTube" width="350" /></a>
14+
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=vt2zsdiNh3U"><img src="https://github.com/user-attachments/assets/82ab2715-727e-4d09-9314-b8905795dc43" title="SeleniumBase on YouTube" width="320" /></a>
1515
<p>(<b><a href="https://www.youtube.com/watch?v=vt2zsdiNh3U">Watch "Hacking websites with CDP" on YouTube! ▶️</a></b>)</p>
1616

1717
--------
1818

19+
<!-- YouTube View --><a href="https://www.youtube.com/watch?v=gEZhTfaIxHQ"><img src="https://github.com/user-attachments/assets/656977e1-5d66-4d1c-9eec-0aaa41f6522f" title="SeleniumBase on YouTube" width="320" /></a>
20+
<p>(<b><a href="https://www.youtube.com/watch?v=gEZhTfaIxHQ">Watch "Web-Scraping with GitHub Actions" on YouTube! ▶️</a></b>)</p>
21+
22+
--------
23+
1924
👤 <b translate="no">UC Mode</b> avoids bot-detection by first disconnecting WebDriver from the browser at strategic times, calling special <code>PyAutoGUI</code> methods to bypass CAPTCHAs (as needed), and finally reconnecting the <code>driver</code> afterwards so that WebDriver actions can be performed again. Although this approach works for bypassing simple CAPTCHAs, more flexibility is needed for bypassing bot-detection on websites with advanced protection. (That's where <b translate="no">CDP Mode</b> comes in.)
2025

2126
🐙 <b translate="no">CDP Mode</b> is based on <a href="https://github.com/HyperionGray/python-chrome-devtools-protocol" translate="no">python-cdp</a>, <a href="https://github.com/HyperionGray/trio-chrome-devtools-protocol" translate="no">trio-cdp</a>, and <a href="https://github.com/ultrafunkamsterdam/nodriver" translate="no">nodriver</a>. <code>trio-cdp</code> is an early implementation of <code>python-cdp</code>, and <code>nodriver</code> is a modern implementation of <code>python-cdp</code>. (Refactored <code>Python-CDP</code> code is imported from <a href="https://github.com/mdmintz/MyCDP" translate="no">MyCDP</a>.)

examples/cdp_mode/raw_glassdoor.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, ad_block=True) as sb:
4+
url = "https://www.glassdoor.com/Reviews/index.htm"
5+
sb.activate_cdp_mode(url)
6+
sb.uc_gui_click_captcha()
7+
sb.highlight('[data-test="global-nav-glassdoor-logo"]')
8+
sb.highlight('[data-test="site-header-companies"]')
9+
sb.highlight('[data-test="search-button"]')
10+
sb.highlight('[data-test="sign-in-button"]')
11+
sb.highlight('[data-test="company-search-autocomplete"]')

examples/raw_invisible_captcha.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, incognito=True) as sb:
4+
url = "https://seleniumbase.io/apps/invisible_recaptcha"
5+
sb.activate_cdp_mode(url)
6+
sb.sleep(1)
7+
sb.assert_element("img#captcha-success", timeout=3)
8+
sb.set_messenger_theme(location="top_left")
9+
sb.post_message("SeleniumBase wasn't detected", duration=3)

examples/raw_recaptcha.py

-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True, test=True, incognito=True) as sb:
4-
url = "https://seleniumbase.io/apps/recaptcha"
5-
sb.activate_cdp_mode(url)
6-
sb.sleep(1)
7-
sb.uc_gui_handle_captcha() # Try with TAB + SPACEBAR
8-
sb.assert_element("img#captcha-success", timeout=3)
9-
sb.set_messenger_theme(location="top_left")
10-
sb.post_message("SeleniumBase wasn't detected", duration=3)
11-
123
with SB(uc=True, test=True, incognito=True) as sb:
134
url = "https://seleniumbase.io/apps/recaptcha"
145
sb.activate_cdp_mode(url)

examples/uc_cdp_events.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from rich.pretty import pprint
22
from seleniumbase import BaseCase
3-
BaseCase.main(__name__, __file__, "--uc", "--uc-cdp", "-s")
3+
BaseCase.main(__name__, __file__, "--uc", "--uc-cdp")
44

55

66
class CDPTests(BaseCase):

examples/verify_undetected.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Some sites use scripts to detect Selenium, and then block you.
33
To evade detection, add --uc as a pytest command-line option."""
44
from seleniumbase import BaseCase
5-
BaseCase.main(__name__, __file__, "--uc", "-s")
5+
BaseCase.main(__name__, __file__, "--uc")
66

77

88
class UndetectedTest(BaseCase):

0 commit comments

Comments
 (0)