70 lines
3.4 KiB
Python
70 lines
3.4 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": 1600, "height": 1100})
|
||
await pg.goto("https://parastoo.zebellkhan.com/", wait_until="networkidle", timeout=90000)
|
||
await pg.wait_for_timeout(3000)
|
||
await pg.click('nav.tabs button[data-view="tasks"]')
|
||
await pg.wait_for_timeout(1800)
|
||
|
||
r = await pg.evaluate("""() => {
|
||
const out = {};
|
||
// (1) grid columns of the category cards
|
||
const grid = document.querySelectorAll('#view-tasks .grid.g2')[0];
|
||
if (grid) {
|
||
const cs = getComputedStyle(grid);
|
||
out.gridCols = cs.gridTemplateColumns.split(' ').length;
|
||
out.gridGap = cs.gap;
|
||
const kids = [...grid.children];
|
||
out.cardCount = kids.length;
|
||
out.topBorders = kids.map(k => getComputedStyle(k).borderTopWidth + ' ' + getComputedStyle(k).borderTopColor);
|
||
// side-by-side check: first two cards share a row (same top offset)
|
||
out.rowGrouping = kids.slice(0,3).map(k => Math.round(k.getBoundingClientRect().top));
|
||
out.cardWidths = kids.slice(0,2).map(k => Math.round(k.getBoundingClientRect().width));
|
||
}
|
||
// (2) card internals
|
||
const c0 = document.querySelector('#view-tasks .grid.g2 .card');
|
||
if (c0) {
|
||
out.card0 = {
|
||
title: c0.querySelector('.card-title')?.innerText,
|
||
tags: [...c0.querySelectorAll('.tag')].map(t=>t.innerText),
|
||
bullets: [...c0.querySelectorAll('li')].map(l=>l.innerText).slice(0,3),
|
||
bulletCount: c0.querySelectorAll('li').length
|
||
};
|
||
}
|
||
// (3) KPI numerals
|
||
out.kpis = [...document.querySelectorAll('#view-tasks .kpi')].map(k => ({
|
||
label: k.querySelector('.kpi-label')?.innerText,
|
||
val: k.querySelector('.kpi-val')?.innerText,
|
||
foot: k.querySelector('.kpi-foot')?.innerText
|
||
}));
|
||
// (4) strategic gaps boxes
|
||
const gaps = document.querySelectorAll('#view-tasks .grid.g3 > div');
|
||
out.gapBoxes = [...gaps].map(g => ({
|
||
head: g.querySelector('div')?.innerText,
|
||
bg: getComputedStyle(g).backgroundColor,
|
||
h: Math.round(g.getBoundingClientRect().height)
|
||
}));
|
||
// (5) clipping / overlap
|
||
const clipped = [];
|
||
document.querySelectorAll('#view-tasks *').forEach(el => {
|
||
const cs = getComputedStyle(el);
|
||
if (el.scrollHeight > el.clientHeight + 3 && (cs.overflowY === 'hidden' || cs.overflow === 'hidden'))
|
||
clipped.push({cls: el.className, t: (el.innerText||'').slice(0,34)});
|
||
if (el.scrollWidth > el.clientWidth + 3 && cs.overflowX === 'hidden' && el.tagName !== 'DIV')
|
||
clipped.push({cls: el.className, t: (el.innerText||'').slice(0,34), axis: 'x'});
|
||
});
|
||
out.clipped = clipped;
|
||
// latin digit leakage in visible text
|
||
const vis = document.getElementById('view-tasks').innerText;
|
||
out.latinDigits = (vis.match(/[0-9]/g)||[]).length;
|
||
out.persianDigits = (vis.match(/[۰-۹]/g)||[]).length;
|
||
return out;
|
||
}""")
|
||
print(json.dumps(r, ensure_ascii=False, indent=2))
|
||
await b.close()
|
||
|
||
asyncio.run(main())
|