Skip to content

Commit be1a182

Browse files
committed
Add new CDP Mode examples
1 parent 1021bc6 commit be1a182

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

examples/cdp_mode/raw_cf.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Using CDP Mode with PyAutoGUI to bypass CAPTCHAs."""
2+
from seleniumbase import SB
3+
4+
with SB(uc=True, test=True, locale_code="en") as sb:
5+
url = "https://www.cloudflare.com/login"
6+
sb.activate_cdp_mode(url)
7+
sb.sleep(2)
8+
sb.uc_gui_handle_captcha() # PyAutoGUI press Tab and Spacebar
9+
sb.sleep(2)
10+
11+
with SB(uc=True, test=True, locale_code="en") as sb:
12+
url = "https://www.cloudflare.com/login"
13+
sb.activate_cdp_mode(url)
14+
sb.sleep(2)
15+
sb.uc_gui_click_captcha() # PyAutoGUI click. (Linux needs it)
16+
sb.sleep(2)

examples/cdp_mode/raw_pixelscan.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, incognito=True, test=True) as sb:
4+
sb.activate_cdp_mode("https://pixelscan.net/")
5+
sb.sleep(3)
6+
sb.remove_elements("div.banner") # Remove the banner
7+
sb.remove_elements("jdiv") # Remove chat widgets
8+
sb.cdp.scroll_down(15)
9+
not_masking_text = "You are not masking your fingerprint"
10+
sb.assert_text(not_masking_text, "pxlscn-fingerprint-masking")
11+
no_automation_detected = "No automation framework detected"
12+
sb.assert_text(no_automation_detected, "pxlscn-bot-detection")
13+
sb.highlight("span.text-success", loops=8)
14+
sb.sleep(1)
15+
fingerprint_masking_div = "pxlscn-fingerprint-masking div"
16+
sb.highlight(fingerprint_masking_div, loops=9)
17+
sb.sleep(1)
18+
sb.highlight(".bot-detection-context", loops=10)
19+
sb.sleep(2)

examples/cdp_mode/raw_res_nike.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Using CDP.network.RequestWillBeSent and CDP.network.ResponseReceived."""
2+
import colorama
3+
import mycdp
4+
import sys
5+
from seleniumbase import SB
6+
7+
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX
8+
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
9+
cr = colorama.Style.RESET_ALL
10+
if "linux" in sys.platform:
11+
c1 = c2 = cr = ""
12+
13+
14+
async def send_handler(event: mycdp.network.RequestWillBeSent):
15+
r = event.request
16+
s = f"{r.method} {r.url}"
17+
for k, v in r.headers.items():
18+
s += f"\n\t{k} : {v}"
19+
print(c1 + "*** ==> RequestWillBeSent <== ***" + cr)
20+
print(s)
21+
22+
23+
async def receive_handler(event: mycdp.network.ResponseReceived):
24+
print(c2 + "*** ==> ResponseReceived <== ***" + cr)
25+
print(event.response)
26+
27+
28+
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
29+
url = "https://www.nike.com/"
30+
sb.activate_cdp_mode(url)
31+
sb.cdp.add_handler(mycdp.network.RequestWillBeSent, send_handler)
32+
sb.cdp.add_handler(mycdp.network.ResponseReceived, receive_handler)
33+
sb.sleep(2.5)
34+
sb.cdp.gui_click_element('div[data-testid="user-tools-container"]')
35+
sb.sleep(1.5)
36+
search = "Nike Air Force 1"
37+
sb.cdp.press_keys('input[type="search"]', search)
38+
sb.sleep(4)
39+
elements = sb.cdp.select_all('ul[data-testid*="products"] figure .details')
40+
if elements:
41+
print('**** Found results for "%s": ****' % search)
42+
for element in elements:
43+
print("* " + element.text)
44+
sb.sleep(2)

0 commit comments

Comments
 (0)