Files
scripts/alojadamaria/capture_alojadamaria_extra.py
T
ealmeida 6035542b67 feat: scripts de projectos vindos do Hub (podcast, alojadamaria, clip, ocr, etc.)
Movidos do vault Hub para centralizar scripts. Hub mantem symlinks.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 20:53:29 +01:00

123 lines
4.8 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Captura detalhes adicionais: hero CTA, produto, footer, barra anúncio
"""
from playwright.sync_api import sync_playwright
import time
OUTPUT_DIR = "/media/ealmeida/Dados/Hub/03-Propostas/ALojaDaMaria/screenshots/alojadamaria"
BASE_URL = "https://alojadamaria.com/"
def crop(page, path, clip):
page.screenshot(path=path, clip=clip, full_page=False)
print(f" Guardado: {path}")
def main():
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
# --- Desktop 1440px ---
ctx = browser.new_context(viewport={"width": 1440, "height": 900}, locale="pt-PT")
page = ctx.new_page()
page.goto(BASE_URL, wait_until="networkidle", timeout=40000)
time.sleep(2)
# Hero completo com CTA visível
page.screenshot(path=f"{OUTPUT_DIR}/desktop_hero_zoom.png",
clip={"x": 0, "y": 0, "width": 1440, "height": 600})
print(" Hero desktop guardado")
# Header/nav
page.screenshot(path=f"{OUTPUT_DIR}/desktop_header.png",
clip={"x": 0, "y": 0, "width": 1440, "height": 80})
print(" Header desktop guardado")
# Barra topo (announcement bar)
page.screenshot(path=f"{OUTPUT_DIR}/desktop_announcebar.png",
clip={"x": 0, "y": 0, "width": 1440, "height": 35})
print(" Barra anúncio guardada")
# Produtos (scroll para secção)
page.evaluate("window.scrollTo(0, 700)")
time.sleep(1)
page.screenshot(path=f"{OUTPUT_DIR}/desktop_produtos.png",
clip={"x": 0, "y": 0, "width": 1440, "height": 900})
print(" Produtos desktop guardados")
# Footer
page.evaluate("window.scrollTo(0, document.body.scrollHeight)")
time.sleep(1)
page.screenshot(path=f"{OUTPUT_DIR}/desktop_footer.png",
clip={"x": 0, "y": 0, "width": 1440, "height": 900})
print(" Footer desktop guardado")
ctx.close()
# --- Mobile 375px ---
ctx_m = browser.new_context(viewport={"width": 375, "height": 812}, locale="pt-PT")
page_m = ctx_m.new_page()
page_m.goto(BASE_URL, wait_until="networkidle", timeout=40000)
time.sleep(2)
# Header mobile
page_m.screenshot(path=f"{OUTPUT_DIR}/mobile_header.png",
clip={"x": 0, "y": 0, "width": 375, "height": 120})
print(" Header mobile guardado")
# Hero mobile
page_m.screenshot(path=f"{OUTPUT_DIR}/mobile_hero.png",
clip={"x": 0, "y": 0, "width": 375, "height": 500})
print(" Hero mobile guardado")
# Produtos mobile
page_m.evaluate("window.scrollTo(0, 500)")
time.sleep(1)
page_m.screenshot(path=f"{OUTPUT_DIR}/mobile_produtos.png",
clip={"x": 0, "y": 0, "width": 375, "height": 812})
print(" Produtos mobile guardados")
# Footer mobile
page_m.evaluate("window.scrollTo(0, document.body.scrollHeight)")
time.sleep(1)
page_m.screenshot(path=f"{OUTPUT_DIR}/mobile_footer.png",
clip={"x": 0, "y": 0, "width": 375, "height": 812})
print(" Footer mobile guardado")
# Tentar obter URL de produto real
links = page_m.query_selector_all("a[href*='product']")
product_url = None
for l in links:
href = l.get_attribute("href")
if href and "product-category" not in href and "alojadamaria.com/product" in href:
product_url = href
break
if product_url:
print(f"\n URL produto encontrado: {product_url}")
page_m.goto(product_url, wait_until="networkidle", timeout=30000)
time.sleep(2)
page_m.screenshot(path=f"{OUTPUT_DIR}/mobile_produto_detalhe_atf.png",
full_page=False)
page_m.screenshot(path=f"{OUTPUT_DIR}/mobile_produto_detalhe_full.png",
full_page=True)
print(" Produto detalhe mobile guardado")
# Desktop produto
ctx_d2 = browser.new_context(viewport={"width": 1440, "height": 900}, locale="pt-PT")
page_d2 = ctx_d2.new_page()
page_d2.goto(product_url, wait_until="networkidle", timeout=30000)
time.sleep(2)
page_d2.screenshot(path=f"{OUTPUT_DIR}/desktop_produto_detalhe_atf.png",
full_page=False)
page_d2.screenshot(path=f"{OUTPUT_DIR}/desktop_produto_detalhe_full.png",
full_page=True)
print(" Produto detalhe desktop guardado")
ctx_d2.close()
ctx_m.close()
browser.close()
print("\nCapturas extra concluídas.")
if __name__ == "__main__":
main()