二、安装 PageEyes Agent

一、Python 环境

需要 Python 3.12 或更高版本。(我用的 3.13 运行会报 No module named 'imghdr'。查后 imghdr 在 3.13 中废弃了)

我用的 conda 虚拟环境,版本检查命令如下:

conda create -n py312 python=3.12
conda activate py312 python -V

显示如下图

image

conda 安装及创建 python 虚拟环境,参见 https://www.cnblogs.com/rslai/p/18741276

二、使用 pip 安装 page-eyes

pip install page-eyes

三、安装 Playwright 浏览器驱动

# 安装 Playwright 浏览器驱动
playwright install

# 如果只需要特定浏览器,可以指定
playwright install chromium

四、运行脚本 

创建一个 unit_01.py  文件,并将如下内容复制进去,注意将 OPENAI_API_KEY 修改为你自己的 API Key

import os
import asyncio

from page_eyes.agent import WebAgent


async def main():
    os.environ["OPENAI_API_KEY"] = "XXX" # 替换为您的 DeepSeek API Key
    os.environ["OPENAI_BASE_URL"] = "https://api.deepseek.com/v1"



    web_agent = await WebAgent.create(simulate_device='Intel MacBook Pro 13-inch', debug=True)

    await web_agent.run(
        """
        - 打开 url "https://wma.wavecommittee.com/"
        - 点击"浪潮评委会成员"tab
        - 上滑页面,直到出现"查看浪潮评委会"
        - 点击"查看浪潮评委会"按钮
        """
    )


if __name__ == "__main__":
    asyncio.run(main())

执行如下命令运行脚本

# 启动 python 3.12 环境
conda activate py312

# 运行脚本
python unit_01.py

此时浏览器可以正常启动,也能正常打开页面,但执行到点击时会报错。原因是没有安装 OmniParserV2。

五、安装 OmniParser 服务

1、克隆 OmniParser 仓库

git clone https://github.com/microsoft/OmniParser.git
cd OmniParser

2、安装依赖

# 启动 python 3.12 环境
conda activate py312

# 安装依赖
pip install -r requirements.txt

3、下载 OmniParser V2 模型权重

# 创建权重目录
mkdir -p weights

# 方法1:从 Hugging Face 下载(推荐)
pip install huggingface_hub

在 OmniParser 目录中创建 download.py 文件,并将如下内容复制进去

from huggingface_hub import snapshot_download

# 下载 V2 版本
model_path = snapshot_download(
    repo_id="microsoft/OmniParser-v2.0",  # 注意是 v2.0
    local_dir="./weights",
    repo_type="model"
)
print(f"模型下载到: {model_path}")

下载模型 

python download.py

模型下载到 weights 目录中,如下图

image

 

posted @ 2026-03-17 15:49  rslai  阅读(5)  评论(0)    收藏  举报