page_00001.py

page_00001.py — 页面交互函数(示例)

实现 crawl_page 页面处理函数(模拟点击/翻页等交互动作)的大公司版示例。

代码

# 进行翻页操作:点击下一页按钮
def crawl_page(page):
    try:
        # 定位标题为“下一页”的按钮
        next_page_button = page.get_by_title("下一页")
        
        # 判断按钮是否存在且可用
        if next_page_button and next_page_button.is_enabled(): 
            # 获取按钮禁用状态属性
            aria_disabled = next_page_button.get_attribute('aria-disabled')
            # 未禁用则点击翻页
            if aria_disabled != 'true':
                next_page_button.click() 
                return True
                
    except Exception as e:
        # 捕获翻页异常并打印
        print(f"翻页时出现错误: {e}")
        
    # 无法翻页返回 False
    return False

项目分区导航gen_00001 ⬅️ | 05-page_00001 | ➡️ auto_on_response