Explorer
/tmp/verify_images_browser.py
← Zurück ↓ Download
import asyncio,json,urllib.request
from playwright.async_api import async_playwright
BASE='https://sma.agentsolutions-mallorca.com'
RSS='41222120-fb41-4fb1-ad14-c8a873b9a0a4'
YT='b08a26eb-05a8-452c-853d-ff6f54f8ad42'
WATCH='ee60e889-b69e-4551-91de-e2e8c3bc50bf'
NOIMG='919a871d-7de7-4335-897f-1e0411b87c42'

async def main():
    async with async_playwright() as pw:
        browser=await pw.chromium.launch(headless=True, executable_path='/snap/bin/chromium', args=['--no-sandbox'])
        page=await browser.new_page()
        out={}
        for days,label in [(1,'1d'),(14,'14d'),(0,'all')]:
            r=await page.goto(f'{BASE}/cockpit?days={days}',wait_until='networkidle',timeout=60000)
            await page.evaluate('window.scrollTo(0, document.body.scrollHeight)')
            await page.wait_for_timeout(1000)
            imgs=page.locator('.sig .thumb img')
            count=await imgs.count()
            widths=[]
            for i in range(count): widths.append(await imgs.nth(i).evaluate('(el)=>({src:el.src,naturalWidth:el.naturalWidth,complete:el.complete})'))
            out[label]={'http':r.status if r else None,'cards':await page.locator('.sig').count(),'img_tags':count,'loaded_images':sum(x['naturalWidth']>0 for x in widths),'images':widths[:10]}
        cases=[(RSS,'rss'),(YT,'youtube'),(WATCH,'watch'),(NOIMG,'no_image')]
        for sid,label in cases:
            r=await page.goto(f'{BASE}/cockpit?highlight={sid}',wait_until='networkidle',timeout=60000)
            card=page.locator(f'#sig-{sid}')
            img=card.locator('img')
            out[label]={'http':r.status if r else None,'card':await card.count(),'img_tags':await img.count(),'naturalWidth':await img.first.evaluate('(el)=>el.naturalWidth') if await img.count() else 0,'symbol_visible':await card.locator('.thumb > span').count() > 0}
        await page.screenshot(path='/tmp/aa045-f8-p3-cockpit.png',full_page=True)
        await browser.close()
    print(json.dumps(out,ensure_ascii=False))
asyncio.run(main())