feat: Agente-Marketing initial commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import re, time, random
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright_stealth import Stealth
|
||||
|
||||
def human_delay(a=1.5, b=3.5):
|
||||
time.sleep(random.uniform(a, b))
|
||||
|
||||
def slow_scroll(page, steps=4):
|
||||
for _ in range(steps):
|
||||
page.mouse.wheel(0, random.randint(300, 700))
|
||||
time.sleep(random.uniform(0.5, 1.0))
|
||||
|
||||
print("=== Test Stealth Playwright - Zillow ===")
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(
|
||||
headless=False,
|
||||
args=["--disable-blink-features=AutomationControlled", "--start-maximized"]
|
||||
)
|
||||
ctx = browser.new_context(
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
|
||||
locale="en-US",
|
||||
timezone_id="America/New_York",
|
||||
viewport={"width": 1366, "height": 768},
|
||||
)
|
||||
page = ctx.new_page()
|
||||
Stealth().apply_stealth_sync(page)
|
||||
|
||||
page.goto("https://www.zillow.com/homes/for_sale/vero-beach-fl/", wait_until="load", timeout=45000)
|
||||
human_delay(2, 4)
|
||||
slow_scroll(page, 5)
|
||||
human_delay(1, 2)
|
||||
|
||||
print("Title:", page.title()[:80])
|
||||
cards = page.query_selector_all("[data-test='property-card']")
|
||||
print(f"Property cards: {len(cards)}")
|
||||
for card in cards[:5]:
|
||||
print(" ", card.inner_text()[:120].replace('\n', ' | '))
|
||||
|
||||
if not cards:
|
||||
content = page.content()
|
||||
prices = re.findall(r'"unformattedPrice":\s*(\d+)', content)
|
||||
print("Prices in HTML:", prices[:5])
|
||||
|
||||
browser.close()
|
||||
|
||||
print("\n=== Test Stealth - Realtor.com ===")
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(
|
||||
headless=False,
|
||||
args=["--disable-blink-features=AutomationControlled", "--start-maximized"]
|
||||
)
|
||||
ctx = browser.new_context(
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
|
||||
locale="en-US",
|
||||
timezone_id="America/New_York",
|
||||
)
|
||||
page = ctx.new_page()
|
||||
Stealth().apply_stealth_sync(page)
|
||||
|
||||
page.goto("https://www.realtor.com/realestateandhomes-search/Vero-Beach_FL/price-na-230000", wait_until="load", timeout=45000)
|
||||
human_delay(2, 4)
|
||||
slow_scroll(page, 5)
|
||||
|
||||
print("Title:", page.title()[:80])
|
||||
cards = page.query_selector_all("[data-testid='property-card-content']")
|
||||
print(f"Cards: {len(cards)}")
|
||||
for card in cards[:3]:
|
||||
print(" ", card.inner_text()[:120].replace('\n', ' | '))
|
||||
|
||||
browser.close()
|
||||
Reference in New Issue
Block a user