56 lines
No EOL
2.6 KiB
Python
56 lines
No EOL
2.6 KiB
Python
import asyncio, json
|
|
from playwright.async_api import async_playwright
|
|
|
|
async def main():
|
|
async with async_playwright() as p:
|
|
b = await p.chromium.launch(args=["--no-sandbox"])
|
|
pg = await b.new_page(viewport={"width": 1500, "height": 1000})
|
|
errs = []
|
|
pg.on("pageerror", lambda e: errs.append(str(e)))
|
|
pg.on("console", lambda m: errs.append(f"C {m.text}") if m.type == "error" else None)
|
|
await pg.goto("https://parastoo.zebellkhan.com/", wait_until="networkidle", timeout=90000)
|
|
await pg.wait_for_timeout(2500)
|
|
await pg.click('#tabs button[data-view="team"]')
|
|
await pg.wait_for_timeout(5000)
|
|
|
|
geo = await pg.evaluate("""() => {
|
|
const out = {cards: [], detail: [], verdict: [], clipped: []};
|
|
document.querySelectorAll('#teamCards .card').forEach(c => {
|
|
const r = c.getBoundingClientRect();
|
|
out.cards.push({
|
|
w: Math.round(r.width), h: Math.round(r.height),
|
|
title: c.querySelector('.card-title')?.innerText.trim(),
|
|
kpis: [...c.querySelectorAll('.kpi')].map(k => ({
|
|
label: k.querySelector('.kpi-label')?.innerText.trim(),
|
|
val: k.querySelector('.kpi-val')?.innerText.trim()
|
|
}))
|
|
});
|
|
});
|
|
document.querySelectorAll('#teamDetail .card').forEach(c => {
|
|
out.detail.push({
|
|
w: Math.round(c.getBoundingClientRect().width),
|
|
title: c.querySelector('.card-title')?.innerText.trim(),
|
|
rows: c.querySelectorAll('.day-row').length
|
|
});
|
|
});
|
|
document.querySelectorAll('#teamVerdict > div').forEach(v => {
|
|
out.verdict.push(v.innerText.replace(/\\s+/g,' ').trim().slice(0,110));
|
|
});
|
|
// clipping detection: any element whose scrollWidth exceeds clientWidth by >2px
|
|
document.querySelectorAll('#view-team *').forEach(el => {
|
|
if (el.scrollWidth - el.clientWidth > 2 && el.clientWidth > 0) {
|
|
out.clipped.push({
|
|
tag: el.tagName, cls: (el.className||'').toString().slice(0,40),
|
|
over: el.scrollWidth - el.clientWidth,
|
|
text: (el.innerText||'').replace(/\\s+/g,' ').slice(0,50)
|
|
});
|
|
}
|
|
});
|
|
out.pageOverflow = document.documentElement.scrollWidth - document.documentElement.clientWidth;
|
|
return out;
|
|
}""")
|
|
print(json.dumps(geo, ensure_ascii=False, indent=2))
|
|
print("errors:", errs[:5])
|
|
await b.close()
|
|
|
|
asyncio.run(main()) |