Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +38 -59
src/streamlit_app.py
CHANGED
|
@@ -1,62 +1,41 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
from playwright.async_api import async_playwright
|
| 3 |
import asyncio
|
| 4 |
-
from io import BytesIO
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
screenshot = await page.screenshot(full_page=True)
|
| 46 |
-
|
| 47 |
-
await context.close()
|
| 48 |
-
await browser.close()
|
| 49 |
-
|
| 50 |
-
return screenshot
|
| 51 |
-
|
| 52 |
-
return asyncio.run(screenshot_async())
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
st.write("Fetching screenshot...")
|
| 56 |
-
img = get_screenshot()
|
| 57 |
-
|
| 58 |
-
if img:
|
| 59 |
-
st.image(BytesIO(img), caption="HiAnime Screenshot", use_column_width=True)
|
| 60 |
-
st.success("Screenshot loaded!")
|
| 61 |
-
else:
|
| 62 |
-
st.error("Failed to capture screenshot.")
|
|
|
|
|
|
|
| 1 |
from playwright.async_api import async_playwright
|
| 2 |
import asyncio
|
|
|
|
| 3 |
|
| 4 |
+
async def debug():
|
| 5 |
+
async with async_playwright() as p:
|
| 6 |
+
browser = await p.chromium.launch(
|
| 7 |
+
headless=True,
|
| 8 |
+
args=["--no-sandbox"]
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
context = await browser.new_context(
|
| 12 |
+
user_agent=(
|
| 13 |
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
| 14 |
+
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
| 15 |
+
"Chrome/120.0.0.0 Safari/537.36"
|
| 16 |
+
),
|
| 17 |
+
viewport={"width": 1366, "height": 768}
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
page = await context.new_page()
|
| 21 |
+
|
| 22 |
+
# 🔴 CORE DEBUG HOOKS
|
| 23 |
+
page.on("framenavigated", lambda frame: print("[NAV]", frame.url))
|
| 24 |
+
page.on("request", lambda req: print("[REQ]", req.method, req.url))
|
| 25 |
+
page.on("response", lambda res: print("[RES]", res.status, res.url))
|
| 26 |
+
page.on("console", lambda msg: print("[CONSOLE]", msg.type, msg.text))
|
| 27 |
+
page.on("pageerror", lambda err: print("[ERROR]", err))
|
| 28 |
+
|
| 29 |
+
print("Opening page...")
|
| 30 |
+
await page.goto(
|
| 31 |
+
"https://hianime.to/watch/naruto-677?ep=12352",
|
| 32 |
+
wait_until="load",
|
| 33 |
+
timeout=60000
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
await page.wait_for_timeout(15000)
|
| 37 |
+
await page.screenshot(path="final.png", full_page=True)
|
| 38 |
+
|
| 39 |
+
await browser.close()
|
| 40 |
+
|
| 41 |
+
asyncio.run(debug())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|