Explorer
/tmp/fbtest3.py
← Zurück ↓ Download
import asyncio, re
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        b = await p.chromium.launch(headless=True)
        ctx = await b.new_context(user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126 Safari/537.36", locale="es-ES")
        pg = await ctx.new_page()
        r = await pg.goto("https://m.facebook.com/murprotec.es/posts/", wait_until="networkidle", timeout=60000)
        await pg.wait_for_timeout(5000)
        print("URL:", pg.url[:100], "HTTP", r.status if r else "?")
        # scrollen
        for i in range(3):
            await pg.mouse.wheel(0, 3000); await pg.wait_for_timeout(2500)
        c = await pg.content()
        links = set(re.findall(r'(?:https://www\.facebook\.com)?/murprotec\.es/(?:posts|videos|photos)/[^"#?\\\s]*', c))
        print("Post-Links nach Scroll:", len(links), list(links)[:4])
        print("Kommentar-Woerter:", len(re.findall(r'comentarios?', c, re.I)))
        # Sichtbarer Text
        txt = await pg.inner_text("body")
        print("TEXT-AUSSCHNITT:", txt[:400].replace("\n"," | ")[:400])
        await b.close()
asyncio.run(main())