Skip to content

Commit 0a196bd

Browse files
committed
Add a Stealthy Playwright example
1 parent 649d439 commit 0a196bd

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from playwright.sync_api import sync_playwright
2+
from seleniumbase import sb_cdp
3+
4+
sb = sb_cdp.Chrome(locale="en", guest=True)
5+
endpoint_url = sb.get_endpoint_url()
6+
7+
with sync_playwright() as p:
8+
browser = p.chromium.connect_over_cdp(endpoint_url)
9+
context = browser.contexts[0]
10+
page = context.pages[0]
11+
page.goto("https://www.walmart.com/")
12+
sb.sleep(3)
13+
page.click('input[aria-label="Search"]')
14+
sb.sleep(1.4)
15+
search = "Settlers of Catan Board Game"
16+
required_text = "Catan"
17+
sb.press_keys('input[aria-label="Search"]', search + "\n")
18+
sb.sleep(3.8)
19+
sb.remove_elements('[data-testid="skyline-ad"]')
20+
sb.remove_elements('[data-testid="sba-container"]')
21+
print('*** Walmart Search for "%s":' % search)
22+
print(' (Results must contain "%s".)' % required_text)
23+
unique_item = []
24+
items = page.locator('div[data-testid="list-view"]')
25+
for i in range(items.count()):
26+
item = items.nth(i)
27+
if required_text in item.inner_text():
28+
description = item.locator('[data-automation-id="product-title"]')
29+
if description and description.inner_text() not in unique_item:
30+
unique_item.append(description.inner_text())
31+
print("* " + description.inner_text())
32+
price = item.locator('[data-automation-id="product-price"]')
33+
if price:
34+
price_text = price.inner_text()
35+
price_text = price_text.split("current price Now ")[-1]
36+
price_text = price_text.split("current price ")[-1]
37+
price_text = price_text.split(" ")[0]
38+
print(" (" + price_text + ")")

0 commit comments

Comments
 (0)