Datasets:
Download scripts/browser_verify.py from bep40/grob-products-updated: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/datasets/bep40/grob-products-updated/resolve/main/scripts/browser_verify.py
- Command line
-
hf download hf://datasets/bep40/grob-products-updated/scripts/browser_verify.py
-
curl -L -o browser_verify.py https://huggingface.co/datasets/bep40/grob-products-updated/resolve/main/scripts/browser_verify.py
2.61 kB
| import asyncio, os | |
| import subprocess, sys | |
| from playwright.async_api import async_playwright | |
| # install browser binary first | |
| subprocess.run([sys.executable, "-m", "playwright", "install", "chromium"], check=True, capture_output=True) | |
| S = "https://bep40-vai-avatar2.hf.space" | |
| async def main(): | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch(headless=True, args=["--no-sandbox","--disable-dev-shm-usage"]) | |
| ctx = await browser.new_context(viewport={"width":1280,"height":900}) | |
| page = await ctx.new_page() | |
| await page.goto(S, wait_until="domcontentloaded", timeout=60000) | |
| await page.wait_for_timeout(6000) | |
| # open Catalogue AI (welcome button or window API) | |
| try: | |
| await page.evaluate("window.openCatalogueAI && window.openCatalogueAI()") | |
| except Exception as e: | |
| print("open err", str(e)[:100]) | |
| await page.wait_for_timeout(5000) | |
| # type search | |
| try: | |
| await page.fill("#cai-q", "kệ nâng hạ") | |
| await page.click("#cai-sb") | |
| except Exception as e: | |
| print("fill err", str(e)[:100]) | |
| await page.wait_for_timeout(4000) | |
| # screenshot whole page | |
| shot = await page.screenshot(full_page=False) | |
| os.makedirs("/tmp/shots", exist_ok=True) | |
| open("/tmp/shots/search.png","wb").write(shot) | |
| print("screenshot bytes:", len(shot)) | |
| # also dump the carousel card texts + img src lengths (from DOM) | |
| info = await page.evaluate("""() => { | |
| const cards = [...document.querySelectorAll('#cai-car > div')]; | |
| return cards.map(c => { | |
| const img = c.querySelector('img'); | |
| const txt = c.innerText.split('\\n').slice(0,3).join(' | '); | |
| return { txt, imgLen: img ? (img.src.length) : 0, imgPrefix: img ? img.src.slice(0,30) : '' }; | |
| }); | |
| }""") | |
| for i, c in enumerate(info): | |
| print(f"card{i}: {c['txt']} imgLen={c['imgLen']} prefix={c['imgPrefix']}") | |
| # upload screenshot | |
| from huggingface_hub import HfApi | |
| api = HfApi(token=os.environ["HF_TOKEN"], endpoint="https://huggingface.co") | |
| api.upload_file(path_or_fileobj=shot, path_in_repo="debug_live/browser_search.png", | |
| repo_id="bep40/grob-products-updated", repo_type="dataset", | |
| commit_message="headless browser search kệ nâng hạ screenshot") | |
| await browser.close() | |
| subprocess.run([sys.executable, "-m", "playwright", "install", "chromium"], check=True, capture_output=True) | |
| asyncio.run(main()) | |
| print("DONE") |