Skip to content

Commit 5968948

Browse files
committed
Update CDP Mode examples
1 parent edefb3d commit 5968948

5 files changed

Lines changed: 46 additions & 5 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import asyncio
2+
from playwright.async_api import async_playwright
3+
from seleniumbase import cdp_driver
4+
5+
6+
async def main():
7+
driver = await cdp_driver.start_async()
8+
endpoint_url = driver.get_endpoint_url()
9+
tab = await driver.get("about:blank")
10+
11+
async with async_playwright() as p:
12+
browser = await p.chromium.connect_over_cdp(endpoint_url)
13+
context = browser.contexts[0]
14+
page = context.pages[0]
15+
url = (
16+
"https://www.gassaferegister.co.uk/gas-safety"
17+
"/gas-safety-certificates-records/building-regulations-certificate"
18+
"/order-replacement-building-regulations-certificate/"
19+
)
20+
await page.goto(url)
21+
await tab.sleep(0.6)
22+
await tab.solve_captcha()
23+
await page.wait_for_selector("#SearchTerm")
24+
await tab.sleep(1.4)
25+
allow_cookies = 'button:contains("Allow all cookies")'
26+
await tab.click_if_visible(allow_cookies, timeout=2)
27+
await tab.sleep(1)
28+
await page.fill("#SearchTerm", "Hydrogen")
29+
await page.click("button.search-button")
30+
await tab.sleep(3)
31+
results = await tab.query_selector_all("div.search-result")
32+
for result in results:
33+
print(result.text.replace(" " * 12, " ").strip() + "\n")
34+
await tab.scroll_down(50)
35+
await tab.sleep(1)
36+
37+
38+
if __name__ == "__main__":
39+
loop = asyncio.new_event_loop()
40+
loop.run_until_complete(main())

examples/cdp_mode/playwright/raw_gas_info_sync.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
"/order-replacement-building-regulations-certificate/"
1515
)
1616
page.goto(url)
17-
sb.sleep(0.5)
17+
sb.sleep(0.6)
1818
sb.solve_captcha()
1919
page.wait_for_selector("#SearchTerm")
20+
sb.sleep(1.4)
2021
allow_cookies = 'button:contains("Allow all cookies")'
2122
sb.click_if_visible(allow_cookies, timeout=2)
2223
sb.sleep(1)

examples/cdp_mode/raw_gas_records.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"/order-replacement-building-regulations-certificate/"
99
)
1010
sb.activate_cdp_mode(url)
11-
sb.sleep(0.5)
11+
sb.sleep(0.6)
1212
sb.solve_captcha()
1313
sb.wait_for_element("#SearchTerm", timeout=5)
14-
sb.sleep(2)
14+
sb.sleep(1.4)
1515
allow_cookies = 'button:contains("Allow all cookies")'
1616
sb.click_if_visible(allow_cookies, timeout=2)
1717
sb.sleep(1)

examples/cdp_mode/raw_kohls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
with SB(uc=True, test=True, locale="en", incognito=True) as sb:
44
url = "https://www.kohls.com/"
5-
sb.activate_cdp_mode(url)
5+
sb.activate_cdp_mode(url, ad_block=True)
66
sb.sleep(2.6)
77
search = "Mickey Mouse Blanket"
88
req_1 = "Mickey"

examples/cdp_mode/raw_pokemon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True, test=True, locale="en", guest=True) as sb:
3+
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
44
url = "https://www.pokemon.com/us"
55
sb.activate_cdp_mode(url)
66
sb.sleep(1.5)

0 commit comments

Comments
 (0)