Skip to content

Commit e6a60b8

Browse files
authored
Merge pull request #4415 from seleniumbase/socks5h-and-pdf-download-updates
Updates for SOCKS5h support and PDF downloads
2 parents d2e98d4 + 17d71ef commit e6a60b8

38 files changed

Lines changed: 387 additions & 234 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ pytest test_coffee_cart.py --trace
763763
--brave # (Shortcut for "--browser=brave".)
764764
--comet # (Shortcut for "--browser=comet".)
765765
--atlas # (Shortcut for "--browser=atlas".)
766+
--chromium # (Shortcut for using base `Chromium`)
766767
--settings-file=FILE # (Override default SeleniumBase settings.)
767768
--env=ENV # (Set the test env. Access with "self.env" in tests.)
768769
--account=STR # (Set account. Access with "self.account" in tests.)

examples/cdp_mode/ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ with SB(uc=True, test=True, ad_block=True) as sb:
297297
sb.click_if_visible('[data-automation-id="sb-btn-close-mark"]')
298298
items = sb.find_elements('[data-item-id]')
299299
for item in items:
300-
if required_text in item.text:
300+
if required_text.lower() in item.text.lower():
301301
description = item.querySelector(
302302
'[data-automation-id="product-title"]'
303303
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import asyncio
2+
import time
3+
from playwright.async_api import async_playwright
4+
from playwright.async_api import expect
5+
from seleniumbase import cdp_driver
6+
7+
8+
async def main():
9+
driver = await cdp_driver.start_async()
10+
endpoint_url = driver.get_endpoint_url()
11+
12+
async with async_playwright() as p:
13+
browser = await p.chromium.connect_over_cdp(endpoint_url)
14+
page = browser.contexts[0].pages[0]
15+
await page.goto("https://pixelscan.net/fingerprint-check")
16+
time.sleep(4)
17+
await expect(
18+
page.locator("pxlscn-bot-detection")
19+
).to_contain_text("No automated behavior", timeout=4000)
20+
await page.wait_for_selector("span.status-success", timeout=4000)
21+
await expect(
22+
page.locator("pxlscn-fingerprint-masking")
23+
).to_contain_text("No masking detected", timeout=4000)
24+
time.sleep(2)
25+
print("Bot Not Detected")
26+
27+
28+
if __name__ == "__main__":
29+
asyncio.run(main())
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from playwright.sync_api import sync_playwright
2+
from playwright.sync_api import expect
3+
from seleniumbase import sb_cdp
4+
5+
sb = sb_cdp.Chrome()
6+
endpoint_url = sb.get_endpoint_url()
7+
8+
with sync_playwright() as p:
9+
browser = p.chromium.connect_over_cdp(endpoint_url)
10+
page = browser.contexts[0].pages[0]
11+
page.goto("https://pixelscan.net/fingerprint-check")
12+
sb.sleep(4)
13+
expect(
14+
page.locator("pxlscn-bot-detection")
15+
).to_contain_text("No automated behavior", timeout=4000)
16+
page.wait_for_selector("span.status-success", timeout=4000)
17+
expect(
18+
page.locator("pxlscn-fingerprint-masking")
19+
).to_contain_text("No masking detected", timeout=4000)
20+
sb.sleep(2)
21+
print("Bot Not Detected")

examples/cdp_mode/playwright/raw_walmart_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
items = page.locator('[data-item-id]')
3434
for i in range(items.count()):
3535
item = items.nth(i)
36-
if required_text in item.inner_text():
36+
if required_text.lower() in item.inner_text().lower():
3737
description = item.locator('[data-automation-id="product-title"]')
3838
if (
3939
description
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from seleniumbase import sb_cdp
2+
3+
sb = sb_cdp.Chrome()
4+
sb.goto("https://www.target.com/")
5+
sb.sleep(1.5)
6+
sb.click("input#search")
7+
sb.sleep(0.5)
8+
search = "Settlers of Catan Board Game"
9+
required_text = "Catan"
10+
sb.type("input#search", search)
11+
sb.sleep(0.5)
12+
sb.click('button[aria-label="search"]')
13+
sb.sleep(2.5)
14+
print('*** Target Search for "%s":' % search)
15+
print(' (Results must contain "%s".)' % required_text)
16+
unique_item_text = []
17+
items = sb.find_elements('[data-test="product-details"]')
18+
for item in items:
19+
if required_text.lower() in item.text.lower():
20+
description = item.querySelector('a[data-test*="Card/title"]')
21+
if description and description.text not in unique_item_text:
22+
unique_item_text.append(description.text)
23+
print("* " + description.text)
24+
price = item.querySelector('[data-test="current-price"]')
25+
if price:
26+
print(" (" + price.text + ")")
27+
item.scroll_into_view()

examples/cdp_mode/raw_cdp_tavus.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/cdp_mode/raw_cdp_walmart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
sb.click_if_visible('[data-automation-id="sb-btn-close-mark"]')
2222
items = sb.find_elements('[data-item-id]')
2323
for item in items:
24-
if required_text in item.text:
24+
if required_text.lower() in item.text.lower():
2525
description = item.querySelector(
2626
'[data-automation-id="product-title"]'
2727
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from seleniumbase import sb_cdp
2+
3+
sb = sb_cdp.Chrome(use_chromium=True, ad_block=True)
4+
sb.goto("https://www.zillow.com/")
5+
sb.sleep(2)
6+
search = "Bar Harbor ME homes on the waterfront"
7+
sb.type('input[aria-label="Search"]', search)
8+
sb.sleep(1)
9+
sb.click('button[type="submit"]')
10+
sb.sleep(2)
11+
sb.click_if_visible('span:contains("Cancel")')
12+
sb.sleep(0.5)
13+
sb.click_if_visible('button[title="Close"]')
14+
items = sb.find_visible_elements('[data-testid="property-card"]')
15+
print('*** %s:' % search)
16+
for i, item in enumerate(items):
17+
print("<----- %s ----->" % (i + 1))
18+
print(item.query_selector('[data-testid*="price"]').text)
19+
print(item.query_selector('[data-testid*="details"]').text)
20+
print(item.query_selector('[data-testid*="address"]').text)
21+
item.scroll_into_view()
22+
print("<-------------->")
23+
sb.sleep(2)
24+
sb.quit()

examples/cdp_mode/raw_indeed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
with SB(uc=True, test=True) as sb:
44
sb.activate_cdp_mode()
55
sb.goto("https://www.indeed.com/companies/search")
6-
sb.sleep(2)
6+
sb.sleep(0.8)
77
sb.solve_captcha()
8-
sb.sleep(1)
8+
sb.sleep(0.8)
99
search_box = "input#company-search"
1010
if not sb.is_element_present(search_box):
1111
sb.solve_captcha()
12-
sb.sleep(1)
12+
sb.sleep(0.8)
1313
company = "NASA Jet Propulsion Laboratory"
1414
sb.click(search_box)
1515
sb.sleep(0.1)

0 commit comments

Comments
 (0)