Spaces:
Running
Running
Download dengtaishan-src/tools/shot.py from Ethscriptions/mx: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/Ethscriptions/mx/resolve/main/dengtaishan-src/tools/shot.py
- Command line
-
hf download hf://spaces/Ethscriptions/mx/dengtaishan-src/tools/shot.py
-
curl -L -o shot.py https://huggingface.co/spaces/Ethscriptions/mx/resolve/main/dengtaishan-src/tools/shot.py
1.19 kB
| # 用无头浏览器截取指定时间点的画面:python3 shot.py out.png "t1,t2,..." [l|p] [width] | |
| import sys, asyncio | |
| from playwright.async_api import async_playwright | |
| async def main(): | |
| out, ts = sys.argv[1], sys.argv[2] | |
| o = sys.argv[3] if len(sys.argv) > 3 else 'l' | |
| w = sys.argv[4] if len(sys.argv) > 4 else '960' | |
| base = sys.argv[5] if len(sys.argv) > 5 else 'http://localhost:5173/' | |
| async with async_playwright() as p: | |
| b = await p.chromium.launch(args=["--use-gl=swiftshader", "--enable-unsafe-swiftshader"]) | |
| pg = await b.new_page(viewport={"width": 2000, "height": 1200}) | |
| logs = [] | |
| pg.on("console", lambda m: logs.append(m.text) if m.type in ("error", "warning") else None) | |
| pg.on("pageerror", lambda e: logs.append("PAGEERROR " + str(e))) | |
| await pg.goto(f"{base}?still={ts}&o={o}&w={w}") | |
| try: | |
| await pg.wait_for_function("document.title==='ready'", timeout=90000) | |
| except Exception as e: | |
| print("timeout", e) | |
| el = await pg.query_selector("canvas") | |
| if el: await el.screenshot(path=out) | |
| for l in logs[:15]: print(l) | |
| await b.close() | |
| asyncio.run(main()) | |