#!/usr/bin/env python3
"""检查第2页的分页结构"""
import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as pw:
        browser = await pw.chromium.launch(headless=True, args=['--no-sandbox'])
        page = await browser.new_page()
        
        # 访问环评公示第1页
        await page.goto('https://www.yanshougs.com/list/4.html', timeout=30000, wait_until='networkidle')
        await page.wait_for_timeout(3000)
        
        # 获取第1页分页数据
        pag1 = await page.evaluate("""() => {
            const sel = document.querySelector('.pagination');
            if (!sel) return 'none';
            return Array.from(sel.querySelectorAll('a')).map(a => ({
                text: a.textContent.trim(),
                href: a.getAttribute('href'),
                cls: a.className
            }));
        }""")
        print(f"第1页分页: {len(pag1)}个链接")
        for p in pag1:
            print(f"  text='{p['text']}' href='{p['href']}'")
        
        # 点击第2页
        await page.click('a[href="/publicity_list?page=2"]')
        await page.wait_for_timeout(5000)
        
        pag2 = await page.evaluate("""() => {
            const sel = document.querySelector('.pagination');
            if (!sel) return 'none';
            return Array.from(sel.querySelectorAll('a')).map(a => ({
                text: a.textContent.trim(),
                href: a.getAttribute('href'),
                cls: a.className
            }));
        }""")
        print(f"\n第2页分页: {len(pag2)}个链接")
        for p in pag2:
            print(f"  text='{p['text']}' href='{p['href']}' cls='{p['cls']}'")
        
        # 当前URL
        print(f"\n当前URL: {page.url}")
        
        await browser.close()

asyncio.run(main())
