Explorer
/proc/114/root/tmp/meta_card_probe.py
← Zurück ↓ Download
import asyncio,json,urllib.parse
from playwright.async_api import async_playwright
async def main():
 async with async_playwright() as p:
  b=await p.chromium.launch(headless=True,executable_path='/snap/bin/chromium',args=['--no-sandbox']); pg=await b.new_page(); q='Murprotec'; u='https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=ES&q='+urllib.parse.quote(q)+'&search_type=keyword_unordered'; await pg.goto(u,wait_until='domcontentloaded',timeout=60000); await pg.wait_for_timeout(5000)
  anc=pg.get_by_text('Library ID: 1505442561215902',exact=True)
  for level in range(1,8):
   anc=anc.locator('xpath=..')
   try:
    print('level',level,'tag',await anc.evaluate('(e)=>e.tagName'),'textlen',len(await anc.inner_text()),'imgs',await anc.locator('img').count())
    if await anc.locator('img').count(): print(await anc.locator('img').evaluate_all('(els)=>els.map(e=>({src:e.src,alt:e.alt}))'))
   except Exception as e: print(e)
  await b.close()
asyncio.run(main())