#!/usr/bin/env python3
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    context = browser.new_context(
        user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
    )
    page = context.new_page()
    
    page.goto('http://www.njls.gov.cn/lsqrmzf/214/228/index_17658.html', 
              wait_until='networkidle', timeout=30000)
    
    print('Title: ' + page.title())
    print('dataCount: ' + str(page.evaluate('window.dataCount')))
    print('totalList: ' + str(page.evaluate('window.totalList')))
    print('pageSize: ' + str(page.evaluate('window.pageSize')))
    
    page_nav = page.query_selector('#pageNav')
    if page_nav:
        print('#pageNav: ' + page_nav.inner_html()[:300])
    else:
        print('#pageNav: NOT FOUND')
    
    page_div = page.query_selector('#page')
    if page_div:
        print('#page HTML: ' + page_div.inner_html()[:300])
    else:
        print('#page: NOT FOUND')
    
    # Get getXxgkListInfo function by loading the JS file
    js_sources = page.evaluate('Array.from(document.querySelectorAll(script)).map(s => s.src).join(\n)')
    print('\n=== Script sources ===')
    print(js_sources)
    
    # Get trspage.js content via fetch
    trs_js = page.evaluate(
