129 lines
3.7 KiB
Markdown
129 lines
3.7 KiB
Markdown
|
|
# 典型场景示例
|
|||
|
|
|
|||
|
|
所有命令统一用 `bash scripts/nb.sh <subcommand>` 调用(Windows 同义 `scripts/nb.cmd`)。
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 1. 淘宝查最近 3 件已购商品
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 1. 打开淘宝(同名 session 自动恢复登录态)
|
|||
|
|
bash scripts/nb.sh open https://www.taobao.com --session=tb-main --headed
|
|||
|
|
|
|||
|
|
# 2. 直接 goto 已购页(绕开头部 hover 触发问题)
|
|||
|
|
bash scripts/nb.sh goto https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm --session=tb-main
|
|||
|
|
|
|||
|
|
# 3. 等加载完
|
|||
|
|
bash scripts/nb.sh wait --session=tb-main --load-state=networkidle
|
|||
|
|
|
|||
|
|
# 4. 拿 ARIA 树(含订单状态、商品名、价格、时间)
|
|||
|
|
bash scripts/nb.sh snapshot --session=tb-main
|
|||
|
|
|
|||
|
|
# 5. 关闭
|
|||
|
|
bash scripts/nb.sh close --session=tb-main
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
snapshot 输出(YAML)示例:
|
|||
|
|
```yaml
|
|||
|
|
- main:
|
|||
|
|
- listitem [ref=e15]:
|
|||
|
|
- text: "城上轻居酒店(成都双流机场簇桥地铁站店)"
|
|||
|
|
- text: "¥99"
|
|||
|
|
- text: "交易成功"
|
|||
|
|
- link "订单详情" [ref=e17]
|
|||
|
|
- listitem [ref=e22]:
|
|||
|
|
- text: "Steam正版 死亡搁浅2"
|
|||
|
|
- text: "¥328"
|
|||
|
|
- text: "退款关闭" # ← 跳过这条
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 2. 小红书养号 — 启动+登录+抓 cookie
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 启动会话(独立指纹+独立 IP)
|
|||
|
|
bash scripts/nb.sh open https://www.xiaohongshu.com \
|
|||
|
|
--session=xhs-001 \
|
|||
|
|
--proxy=http://user:pass@proxy.example.com:8080 \
|
|||
|
|
--fingerprint-seed=10001 \
|
|||
|
|
--headed
|
|||
|
|
|
|||
|
|
# 看登录入口
|
|||
|
|
bash scripts/nb.sh snapshot --session=xhs-001
|
|||
|
|
|
|||
|
|
# 拟人化点登录、填手机号
|
|||
|
|
bash scripts/nb.sh click e1 --session=xhs-001
|
|||
|
|
bash scripts/nb.sh fill e2 13800001234 --session=xhs-001
|
|||
|
|
|
|||
|
|
# 等用户在浏览器里完成扫码/验证码
|
|||
|
|
# (AI 应该等用户确认后再继续)
|
|||
|
|
|
|||
|
|
# 保存登录态供下次复用
|
|||
|
|
bash scripts/nb.sh state-save --session=xhs-001
|
|||
|
|
bash scripts/nb.sh cookie-list --session=xhs-001 --domain=xiaohongshu.com
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 3. 触发 hover 下拉菜单(淘宝头部、京东个人中心等)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 直接 click 头部"已买到"不跳转,因为它是 hover 触发的下拉
|
|||
|
|
# 正确做法:先 hover 父菜单 → wait → snapshot → click 下拉项
|
|||
|
|
|
|||
|
|
bash scripts/nb.sh hover e10 --session=tb-main # hover "我的淘宝"
|
|||
|
|
bash scripts/nb.sh wait --session=tb-main --timeout=1000
|
|||
|
|
bash scripts/nb.sh snapshot --session=tb-main # 此时下拉已展开
|
|||
|
|
bash scripts/nb.sh click e234 --session=tb-main # 下拉项 ref
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 4. 表单填写(验证码 + 提交)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
bash scripts/nb.sh fill e5 "username@example.com" --session=form-1
|
|||
|
|
bash scripts/nb.sh fill e6 "password123" --session=form-1
|
|||
|
|
bash scripts/nb.sh check e7 --session=form-1 # 勾选"记住我"
|
|||
|
|
bash scripts/nb.sh select e8 "中国" --session=form-1 # 国家下拉
|
|||
|
|
bash scripts/nb.sh press Tab --session=form-1 # 切到下一个输入
|
|||
|
|
bash scripts/nb.sh fill e9 "1234" --session=form-1 # 验证码
|
|||
|
|
bash scripts/nb.sh click e10 --session=form-1 # 提交
|
|||
|
|
bash scripts/nb.sh wait --session=form-1 --load-state=networkidle
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 5. 滚动加载更多(无限滚动列表)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 滚动 800px 等触发懒加载
|
|||
|
|
bash scripts/nb.sh scroll 800 --session=feed --mode=full
|
|||
|
|
bash scripts/nb.sh wait --session=feed --load-state=networkidle
|
|||
|
|
bash scripts/nb.sh snapshot --session=feed
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 6. 截图调试(看不懂 snapshot 时)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 截当前视口
|
|||
|
|
bash scripts/nb.sh screenshot --session=tb-main --out=current.png
|
|||
|
|
|
|||
|
|
# 截整页(含视口外)
|
|||
|
|
bash scripts/nb.sh screenshot --session=tb-main --full-page --out=full.png
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 7. 拿现有 session 列表(避免重复打开)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
bash scripts/nb.sh list
|
|||
|
|
# {data: [{sessionName: "tb-main", url: "...", pageCount: 1, ...}]}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
如果目标 session 已存在 → 跳过 open,直接 snapshot/click。
|