149 lines
4.1 KiB
Markdown
149 lines
4.1 KiB
Markdown
# VisionL 使用示例
|
|
|
|
> 基于实际测试验证的场景。
|
|
|
|
## 场景一:搜索引擎查询
|
|
|
|
```bash
|
|
# 1. 打开百度
|
|
curl -s -X POST http://127.0.0.1:9527/pages \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"url":"https://www.baidu.com","alias":"search"}'
|
|
|
|
# 2. 获取首页文本
|
|
curl -s http://127.0.0.1:9527/pages/search/text
|
|
|
|
# 3. 输入搜索词并搜索
|
|
curl -s -X POST http://127.0.0.1:9527/pages/search/type \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"selector":"#kw","text":"VisionL 浏览器"}'
|
|
curl -s -X POST http://127.0.0.1:9527/pages/search/click \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"selector":"#su"}'
|
|
curl -s -X POST http://127.0.0.1:9527/pages/search/wait \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"ms":2000}'
|
|
|
|
# 4. 获取搜索结果
|
|
curl -s http://127.0.0.1:9527/pages/search/text
|
|
|
|
# 5. 截图保存
|
|
curl -s http://127.0.0.1:9527/pages/search/screenshot | jq -r '.data.base64' | base64 -d > result.png
|
|
|
|
# 6. 关闭
|
|
curl -s -X DELETE http://127.0.0.1:9527/pages/search
|
|
```
|
|
|
|
## 场景二:多页面信息收集
|
|
|
|
```bash
|
|
# 同时打开多个信息源
|
|
curl -s -X POST http://127.0.0.1:9527/pages \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"url":"https://www.baidu.com","alias":"baidu"}'
|
|
curl -s -X POST http://127.0.0.1:9527/pages \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"url":"https://www.bing.com","alias":"bing"}'
|
|
|
|
# 分别提取内容
|
|
curl -s http://127.0.0.1:9527/pages/baidu/text
|
|
curl -s http://127.0.0.1:9527/pages/bing/text
|
|
|
|
# 查看所有页面
|
|
curl -s http://127.0.0.1:9527/pages
|
|
|
|
# 关闭指定页面
|
|
curl -s -X DELETE http://127.0.0.1:9527/pages/baidu
|
|
```
|
|
|
|
## 场景三:Cookie 管理
|
|
|
|
```bash
|
|
# 查看页面 Cookie(百度首页返回 8 个 Cookie)
|
|
curl -s http://127.0.0.1:9527/pages/baidu/cookies
|
|
|
|
# 设置自定义 Cookie
|
|
curl -s -X POST http://127.0.0.1:9527/pages/baidu/cookies \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"name":"session","value":"abc123","domain":".baidu.com"}'
|
|
|
|
# 删除特定 Cookie
|
|
curl -s -X DELETE http://127.0.0.1:9527/pages/baidu/cookies/session
|
|
```
|
|
|
|
## 场景四:网络请求监控
|
|
|
|
```bash
|
|
# 打开页面后查看网络请求日志
|
|
curl -s http://127.0.0.1:9527/pages/baidu/network
|
|
|
|
# 返回包含请求 URL、方法、状态码等信息:
|
|
# [{"type":"response","url":"https://pss.bdstatic.com/...","status":200,...}]
|
|
```
|
|
|
|
## 场景五:JS 数据提取
|
|
|
|
```bash
|
|
# 获取页面标题
|
|
curl -s -X POST http://127.0.0.1:9527/pages/baidu/eval \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"code":"document.title"}'
|
|
# {"ok":true,"data":{"result":"百度一下,你就知道"}}
|
|
|
|
# 获取链接数量
|
|
curl -s -X POST http://127.0.0.1:9527/pages/baidu/eval \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"code":"document.querySelectorAll(\"a\").length"}'
|
|
|
|
# 获取页面 meta 信息
|
|
curl -s -X POST http://127.0.0.1:9527/pages/baidu/eval \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"code":"document.querySelector(\"meta[name=description]\")?.content"}'
|
|
```
|
|
|
|
## 场景六:滚动截图
|
|
|
|
```bash
|
|
# 滚动页面
|
|
curl -s -X POST http://127.0.0.1:9527/pages/baidu/scroll \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"deltaY":500}'
|
|
|
|
# 滚动到底部
|
|
curl -s -X POST http://127.0.0.1:9527/pages/baidu/scroll \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"toBottom":true}'
|
|
|
|
# 截图
|
|
curl -s http://127.0.0.1:9527/pages/baidu/screenshot | jq -r '.data.base64' | base64 -d > scrolled.png
|
|
```
|
|
|
|
## 场景七:切换指纹配置
|
|
|
|
```bash
|
|
# 查看可用配置
|
|
curl -s http://127.0.0.1:9527/profiles
|
|
|
|
# 使用 Windows Chrome 指纹打开页面
|
|
curl -s -X POST http://127.0.0.1:9527/pages \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"url":"https://www.baidu.com","alias":"win","profile":"desktop-windows"}'
|
|
```
|
|
|
|
## 场景八:页面持久化验证
|
|
|
|
```bash
|
|
# 1. 打开页面
|
|
curl -s -X POST http://127.0.0.1:9527/pages \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"url":"https://www.baidu.com","alias":"persistent"}'
|
|
|
|
# 2. 关闭 curl 连接(页面不消失)
|
|
# 3. 重新查询 — 页面仍在
|
|
curl -s http://127.0.0.1:9527/pages/persistent
|
|
# {"ok":true,"data":{"id":"p_xxx","status":"active",...}}
|
|
|
|
# 4. 只有显式 kill 才关闭
|
|
curl -s -X DELETE http://127.0.0.1:9527/pages/persistent
|
|
```
|