一个使用 json 语法糖去执行 puppeteer 的框架。
你可以使用 json 去执行 puppeteer , 就像使用 javascript 去执行 puppeteer 一样
                        
                            
                                本项目默认您已经了解 puppeteer 以及 nodejs 等框架。
 
安装
使用命令行
| 12
 3
 4
 5
 6
 
 | # 执行 jpptr 的配置文件npx jpptr <file> [options]
 # 执行单个带有动作的文件
 npx jpptr exec <file> [options]
 # 查看帮助
 npx jpptr -h
 
 | 
启动配置文件
| 12
 3
 4
 
 | # 启动配置文件, 默认的文件为 jpptr.config.jsonnpx jpptr
 # 如果配置文件不存在,请给出路径
 npx jpptr ./src/jpptr.config.json
 
 | 
启动单个动作文件
| 1
 | npx jpptr exec ./test.json
 | 
ESM
启动配置文件
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 
 | import { Jpptr } from "jpptr";import path from "path";
 
 (async () => {
 
 
 
 
 
 
 
 
 await Jpptr.launch("./jpptr.config.json");
 })();
 
 | 
启动单个文件
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 
 | import { Jpptr } from "jpptr";import path from "path";
 
 async function start() {
 
 
 
 
 
 
 
 
 const jpptr = Jpptr.from("./test.json");
 
 const execute = await jpptr.createExecutor();
 
 await execute.executeAll();
 }
 
 start();
 
 | 
commonjs
使用 require , 其余操作跟 ESM 一样
| 12
 3
 
 | const { Jpptr } = require("jpptr");
 const path = require("path");
 
 | 
配置文件
配置文件用于指定需要执行的动作文件,以及一些全局配置
jpptr.config.json| 12
 3
 4
 5
 6
 
 | {"name": "my jpptr config",
 "version": "1.0.0",
 "include": ["./src/**/*.json", "./test.json"],
 "exclude": ["node_modules/**/*"]
 }
 
 | 
 
动作文件
一般带有 launch 启动参数,以及 actions 动作列表,的 json 文件,我们称为动作文件
- 
launch : puppeteer 启动参数 
- 
actions : 动作列表 
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 
 | {
 "launch": {
 "executablePath": "C:/Program Files/Google/Chrome/Application/chrome.exe",
 "defaultViewport": null,
 "headless": false
 },
 "actions": [
 
 ["goto", "https://enncy.github.io/jpptr/test.html"],
 
 ["type", "#username", "enncy"],
 
 ["type", "#password", "123456"],
 
 ["click", "#submit"],
 
 ["waitForTimeout", 3000]
 
 ["close"]
 ]
 }
 
 | 
动作(Actions)
动作是 jpptr 的核心事件
一个动作对应着浏览器中的操作,例如点击,输入,跳转
动作可以表示成一个数组 : [puppeteer 方法, …方法的其余参数]
| 1
 | ["goto", "https://enncy.github.io/jpptr/test.html"]
 | 
jpptr 会使用 ArrayParser 将其解析成可以执行的动作对象
| 12
 3
 4
 5
 
 | {"use": "function",
 "name": "goto",
 "args": ["https://enncy.github.io/jpptr/test.html"]
 }
 
 | 
其中
- use: 是使用插件
- function: 是 方法插件 专门执行 puppeteer 的方法
- name: 是 puppeteer 的方法名
- args: 是 puppeteer 方法名的参数列表
详细文档 : /jpptr-docs/action/
解析器(Parser)
解析器用于解析 动作文件
详细文档 : /jpptr-docs/parser/
插件(Plugin)
- 插件也可以解析 动作文件
- 插件有控制 puppeteer 的权限, 例如 browser, page, frame 等
- 插件可以返回新的 browser, page, frame 以及 actions(子动作)
- jpptr 会根据返回的 actions 继续生成新的动作,并且执行
详细文档 : /jpptr-docs/plugin/