-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
API Invoke Example
假设有3个输入参数可以被修改,其调用名称分别为:urlList_0
,loopTimes_循环_1
,inputText_2
分别表示打开网页
操作的网址列表,循环点击下一页
操作的点击次数以及输入文字
操作的输入值,我们分别要输入的值示例如下:

则在POSTMAN中,可以设置以下配置来获得新的任务ID:
- 调用方法:
POST
- 调用地址:
http://localhost:8074/invokeTask
- Body字段类型:
x-www-form-urlencoded
- 键值对:
-
id
: 任务的id号,在API调用网址后面写了id=ID
: -
paras
: 一个被JSON.stringfy后的键值对对象,包含了所有输入参数的参数值:{"urlList_0":"https://www.baidu.com/s?wd=1\r\nhttps://www.baidu.com/s?wd=1\r\nhttps://www.baidu.com/s?wd=3","loopTimes_循环_1":"15","inputText_2":"TEST"}
-
示例截图如下:
全部配置完成后点击发送请求按钮,如果成功,会得到一个任务ID号:
即可通过此ID,配合命令行执行的命令来执行任务,如执行任务ID号为3的命令为:
cd 你的EasySpider文件夹,如cd D:\Document\Projects\EasySpider
./EasySpider/resources/app/chrome_win64/easyspider_executestage.exe --id [37] --user_data 0 --server_address http://localhost:8074 --config_folder "D:/Document/Projects/EasySpider/ElectronJS/" --headless 0 --read_type remote --config_file_name config.json --saved_file_name
如果想要通过API调用的方式获得任务执行ID,可以参考以下文件:
https://github.com/NaiboWang/EasySpider/blob/v0.3.1/ElectronJS/src/taskGrid/invokeTask.html
参考此文件的第237行开始的localExecuteInstant
方法的POST调用案例:
var para = {};
var t = $('#form').serializeArray();
t.forEach(function (item, index) {
para[item.name] = item.value;
});
$.post("http://localhost:8074/invokeTask", {
id: TASKID, //这里写任务ID号,如1
paras: JSON.stringify(para)
}, function (EID) {
console.log("任务ID为:", EID);
});
以上POST
请求将返回任务执行IDexecution_ID
,接下来使用命令行传入此ID即可执行任务。
后台处理逻辑在以下文件的第223行:
https://github.com/NaiboWang/EasySpider/blob/v0.3.1/ElectronJS/server.js
Click Pages
above to see more pages