Explorer
/proc/1357821/root/tmp/p7_targeted.py
← Zurück ↓ Download
import asyncio,urllib.parse,json,re
from playwright.async_api import async_playwright
qs=[('Murprotec','facebook','site:facebook.com/murprotec.es/posts'),('Murprotec','linkedin','site:linkedin.com/posts/murprotec'),('Murprotec','instagram','site:instagram.com/murprotec (site:instagram.com/p OR site:instagram.com/reel)'),('HUMICONTROL','facebook','site:facebook.com HUMICONTROL posts'),('HUMICONTROL','linkedin','site:linkedin.com HUMICONTROL posts'),('HUMICONTROL','instagram','site:instagram.com HUMICONTROL')]
async def main():
 out=[]
 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()
  for e,plat,q in qs:
   rec={'entity':e,'platform':plat,'query':q}
   try:
    r=await pg.goto('https://www.social-searcher.com/google-social-search/?q='+urllib.parse.quote(q),wait_until='domcontentloaded',timeout=30000); await pg.wait_for_timeout(1800)
    fs=[f for f in pg.frames if plat+'cse.html' in f.url]; f=fs[0] if fs else None
    text=await f.locator('body').inner_text() if f else ''
    links=await f.locator('a').evaluate_all('(els)=>els.map(a=>({url:a.href,text:(a.innerText||a.textContent||"").trim()})).filter(x=>x.url)') if f else []
    rec.update({'http':r.status,'body':text[:12000],'links':[x for x in links if plat+'.com' in x['url']][:100]})
   except Exception as ex:rec['error']=str(ex)
   out.append(rec); print(e,plat,len(rec.get('links',[])),rec.get('http'))
  await b.close()
 json.dump(out,open('/tmp/p7_targeted.json','w'),ensure_ascii=False,indent=2)
asyncio.run(main())