import io, json from playwright.sync_api import sync_playwright SITES = { 'roche': 'https://careers.roche.com/global/en/search-results?keywords=&locationsearch=Switzerland', 'meta': 'https://www.metacareers.com/jobs?offices[0]=Zurich%2C%20Switzerland', 'apple': 'https://jobs.apple.com/en-us/search?location=switzerland-CHE', } out = io.open('_fix_out.txt', 'w', encoding='utf-8') with sync_playwright() as p: b = p.chromium.launch() for k, u in SITES.items(): pg = b.new_page(); calls = [] def on_resp(r, calls=calls): ct = r.headers.get('content-type', '') if 'json' in ct and r.request.method in ('GET', 'POST'): calls.append((r.request.method, r.url, r.request.post_data)) pg.on('response', on_resp) try: pg.goto(u, wait_until='domcontentloaded', timeout=60000) pg.wait_for_timeout(9000) pg.mouse.wheel(0, 5000); pg.wait_for_timeout(4000) out.write('== %s\n' % k) for m, url, pd in calls: if any(w in url.lower() for w in ('search', 'job', 'graphql', 'widget', 'role')): out.write(' %s %s\n' % (m, url[:190])) if pd: out.write(' POST %s\n' % pd[:600]) except Exception as e: out.write('== %s ERR %s\n' % (k, str(e)[:150])) pg.close() b.close() out.close()