mirror of
https://github.com/NaiboWang/EasySpider.git
synced 2025-04-22 08:27:27 +08:00
试运行JS增加显示返回值功能,且可以试运行提取数据操作中的JS
This commit is contained in:
parent
4f858ffee1
commit
499c3f21b6
@ -787,7 +787,41 @@ async function beginInvoke(msg, ws) {
|
||||
let waitTime = parameters.waitTime;
|
||||
let element = await driver.findElement(By.tagName("body"));
|
||||
if (codeMode == 0) {
|
||||
await execute_js(code, element, waitTime);
|
||||
let result = await execute_js(code, element, waitTime);
|
||||
let level = "success";
|
||||
if (result == -1) {
|
||||
level = "info";
|
||||
}
|
||||
if (result != null) {
|
||||
notify_browser(
|
||||
"JavaScript操作返回结果:" + result,
|
||||
"JavaScript operation returns result: " + result,
|
||||
level
|
||||
);
|
||||
}
|
||||
} else if (codeMode == 2) { // 循环内的JS代码
|
||||
let parent_node = JSON.parse(msg.message.parentNode);
|
||||
let parent_xpath = parent_node.parameters.xpath;
|
||||
if (parent_node.parameters.loopType == 2) {
|
||||
parent_xpath = parent_node.parameters.pathList
|
||||
.split("\n")[0]
|
||||
.trim();
|
||||
}
|
||||
let elementInfo = {iframe: parameters.iframe, xpath: parent_xpath, id: -1};
|
||||
let element = await findElementAcrossAllWindows(
|
||||
elementInfo, notifyBrowser = false); //通过此函数找到元素并切换到对应的窗口
|
||||
let result = await execute_js(code, element, waitTime);
|
||||
let level = "success";
|
||||
if (result == -1) {
|
||||
level = "info";
|
||||
}
|
||||
if (result != null) {
|
||||
notify_browser(
|
||||
"JavaScript操作返回结果:" + result,
|
||||
"JavaScript operation returns result: " + result,
|
||||
level
|
||||
);
|
||||
}
|
||||
} else if (codeMode == 8) {
|
||||
//刷新页面
|
||||
try {
|
||||
@ -860,8 +894,8 @@ async function beginInvoke(msg, ws) {
|
||||
} else if (option == 11) {
|
||||
//单个提取数据参数
|
||||
notify_browser(
|
||||
"提示:提取数据操作只能试运行设置的JavaScript语句,且只针对第一个匹配的元素。",
|
||||
"Hint: can only test JavaScript statement set in the data extraction operation, and only for the first matching element.",
|
||||
"提示:提取数据字段的试运行操作只能测试设置的JavaScript语句,且只针对第一个匹配的元素。",
|
||||
"Hint: can only test JavaScript statement set in the data extraction field operation, and only for the first matching element.",
|
||||
"info"
|
||||
);
|
||||
let params = parameters.params; //所有的提取数据参数
|
||||
@ -885,6 +919,20 @@ async function beginInvoke(msg, ws) {
|
||||
);
|
||||
if (element != null) {
|
||||
await execute_js(param.beforeJS, element, param.beforeJSWaitTime);
|
||||
if(param.contentType == 9){ //针对元素的JavaScript代码返回值
|
||||
let result = await execute_js(param.JS, element);
|
||||
let level = "success";
|
||||
if (result == -1) {
|
||||
level = "info";
|
||||
}
|
||||
if (result != null) {
|
||||
notify_browser(
|
||||
"JavaScript操作返回结果:" + result,
|
||||
"JavaScript operation returns result: " + result,
|
||||
level
|
||||
);
|
||||
}
|
||||
}
|
||||
await execute_js(param.afterJS, element, param.afterJSWaitTime);
|
||||
}
|
||||
}
|
||||
|
@ -243,6 +243,7 @@
|
||||
<p><button type="button" data-toggle="modal" data-target="#myModal_XPath" @click="changeXPaths(params.parameters[paraIndex]['allXPaths'])" class="btn btn-primary" style="margin-top: 10px">Click here to view other equivalent XPath expressions</button></p>
|
||||
<label>Final XPath of this field when the task is running:</label>
|
||||
<textarea spellcheck="false" onkeydown="inputDelete(event)" class="form-control" rows="2" readonly style="background:ghostwhite">{{getFinalXPath(params.parameters[paraIndex]['relativeXPath'], params.parameters[paraIndex]['relative'])}}</textarea>
|
||||
<div style="margin-top: 10px"><a href="#" v-on:mousedown="trailParam(paraIndex)" style="text-decoration: none">Trail Run</a></div>
|
||||
<p style="margin-top: 10px">
|
||||
<a class="btn btn-primary" data-toggle="collapse" href="#elementAdvanced" role="button" aria-expanded="false" aria-controls="collapseExample">
|
||||
Click here to expand/collapse advanced operations
|
||||
@ -250,7 +251,6 @@
|
||||
</p>
|
||||
<div :class="{collapse: true, 'show': params.parameters[paraIndex]['beforeJS'].length!=0 || params.parameters[paraIndex]['afterJS'].length!=0}" id="elementAdvanced">
|
||||
<div>
|
||||
<div><a href="#" v-on:mousedown="trailParam(paraIndex)" style="text-decoration: none">Trail Run</a></div>
|
||||
<label>Execute a JavaScript script <strong>before</strong> extracting data from this element: </label>
|
||||
<textarea spellcheck=false onkeydown="inputDelete(event)" class="form-control" rows="2"
|
||||
placeholder='The element should be represented by arguments[0]. Here is an example JavaScript code: arguments[0].innerText = arguments[0].innerText.replace("United States","US"). This code replaces occurrences of "United States" with "US" in the text of the element. Subsequently, when extracting data, you will obtain the replaced value.' v-model='params.parameters[paraIndex]["beforeJS"]'></textarea>
|
||||
|
@ -175,7 +175,7 @@ let app = new Vue({
|
||||
this.nowNode["title"] = LANG("运行操作系统命令", "Run OS Command");
|
||||
break;
|
||||
case 2:
|
||||
this.nowNode["title"] = LANG("执行JavaScript", "Run JavaScript");
|
||||
this.nowNode["title"] = LANG("循环内元素执行JS", "Run JS in Loop");
|
||||
break;
|
||||
case 3:
|
||||
this.nowNode["title"] = LANG("退出循环", "Exit Loop");
|
||||
@ -505,7 +505,7 @@ function elementDblClick(e) {
|
||||
showInfo(LANG("试运行功能不适用于循环操作,请试运行循环内部的具体操作,如点击元素。", "The trial run function is not applicable to loop operations. Please try to run the specific operations in the loop, such as clicking elements."));
|
||||
}
|
||||
} else {
|
||||
if (nodeType == 5 && (app._data.nowNode["parameters"]["codeMode"] != 0 && app._data.nowNode["parameters"]["codeMode"] != 8)) {
|
||||
if (nodeType == 5 && (app._data.nowNode["parameters"]["codeMode"] != 0 && app._data.nowNode["parameters"]["codeMode"] != 2 && app._data.nowNode["parameters"]["codeMode"] != 8)) {
|
||||
showInfo(LANG("试运行自定义操作功能只适用于执行JavaScript和刷新页面操作。", "The trial run custom action function is only applicable to run JavaScript and refresh page operations."));
|
||||
} else {
|
||||
trailElement(app._data.nowNode, 1);
|
||||
|
@ -243,6 +243,7 @@
|
||||
<p><button type="button" data-toggle="modal" data-target="#myModal_XPath" @click="changeXPaths(params.parameters[paraIndex]['allXPaths'])" class="btn btn-primary" style="margin-top: 10px">点此查看其他等价的XPath</button></p>
|
||||
<label>任务运行时最终定位的本字段XPath:</label>
|
||||
<textarea spellcheck=false onkeydown="inputDelete(event)" class="form-control" rows="2" readonly style="background:ghostwhite">{{getFinalXPath(params.parameters[paraIndex]['relativeXPath'], params.parameters[paraIndex]['relative'])}}</textarea>
|
||||
<div style="margin-top: 10px"><a href="#" v-on:mousedown="trailParam(paraIndex)" style="text-decoration: none">试运行</a></div>
|
||||
<p style="margin-top: 10px">
|
||||
<a class="btn btn-primary" data-toggle="collapse" href="#elementAdvanced" role="button" aria-expanded="false" aria-controls="collapseExample">
|
||||
点此展开/折叠自定义操作
|
||||
@ -250,7 +251,6 @@
|
||||
</p>
|
||||
<div :class="{collapse: true, 'show': params.parameters[paraIndex]['beforeJS'].length!=0 || params.parameters[paraIndex]['afterJS'].length!=0}" id="elementAdvanced">
|
||||
<div>
|
||||
<div><a href="#" v-on:mousedown="trailParam(paraIndex)" style="text-decoration: none">试运行</a></div>
|
||||
<label>提取该元素数据<strong>前</strong>针对该元素执行一段JavaScript脚本: </label>
|
||||
<textarea spellcheck=false onkeydown="inputDelete(event)" class="form-control" rows="2"
|
||||
placeholder='该元素用arguments[0]来表示,示例JS代码:arguments[0].innerText = arguments[0].innerText.replace("上海","Shanghai")即实现了将元素文字中的“上海”替换成”Shanghai“的功能,然后后续如提取数据时就会提取到替换后的值。' v-model='params.parameters[paraIndex]["beforeJS"]'></textarea>
|
||||
|
@ -167,7 +167,7 @@
|
||||
},
|
||||
modifyTask: function (index, row) {
|
||||
let id = row.id;
|
||||
let url = row.url;
|
||||
let url = row.links.split("\n")[0];
|
||||
console.log(index, row)
|
||||
let message = { //显示flowchart
|
||||
type: 1, //消息类型,传递链接
|
||||
|
1
ElectronJS/tasks/315.json
Normal file
1
ElectronJS/tasks/315.json
Normal file
@ -0,0 +1 @@
|
||||
{"id":315,"name":"京东全球版-专业的综合网上购物商城","url":"https://www.jd.com","links":"https://www.jd.com","create_time":"2023-12-29 22:34:23","update_time":"2023-12-29 22:38:36","version":"0.6.0","saveThreshold":10,"quitWaitTime":60,"environment":0,"maximizeWindow":0,"maxViewLength":15,"recordLog":1,"outputFormat":"xlsx","saveName":"current_time","dataWriteMode":1,"inputExcel":"","startFromExit":0,"pauseKey":"p","containJudge":false,"browser":"chrome","removeDuplicate":0,"desc":"https://www.jd.com","inputParameters":[{"id":0,"name":"urlList_0","nodeId":1,"nodeName":"打开网页","value":"https://www.jd.com","desc":"要采集的网址列表,多行以\\n分开","type":"text","exampleValue":"https://www.jd.com"}],"outputParameters":[{"id":0,"name":"Text","desc":"自定义操作返回的数据","type":"text","recordASField":1,"exampleValue":""},{"id":1,"name":"Link","desc":"自定义操作返回的数据","type":"text","recordASField":1,"exampleValue":""}],"graph":[{"index":0,"id":0,"parentId":0,"type":-1,"option":0,"title":"root","sequence":[1,2],"parameters":{"history":1,"tabIndex":0,"useLoop":false,"xpath":"","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0},"isInLoop":false},{"id":1,"index":1,"parentId":0,"type":0,"option":1,"title":"打开网页","sequence":[],"isInLoop":false,"position":0,"parameters":{"useLoop":false,"xpath":"","wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"url":"https://www.jd.com","links":"https://www.jd.com","maxWaitTime":10,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"cookies":""}},{"id":2,"index":2,"parentId":0,"type":1,"option":8,"title":"循环点击每个元素","sequence":[4,5,3],"isInLoop":false,"position":1,"parameters":{"history":4,"tabIndex":-1,"useLoop":false,"xpath":"/html/body/div[5]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div/a","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"loopType":1,"pathList":"","code":"","waitTime":0,"exitCount":0,"exitElement":"//body","historyWait":2,"breakMode":0,"breakCode":"","breakCodeWaitTime":0,"skipCount":0,"allXPaths":""}},{"id":5,"index":3,"parentId":2,"type":0,"option":2,"title":"点击元素","sequence":[],"isInLoop":true,"position":2,"parameters":{"history":4,"tabIndex":-1,"useLoop":true,"xpath":"","iframe":false,"wait":2,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"clickWay":0,"newTab":1,"maxWaitTime":10,"params":[],"alertHandleType":0,"allXPaths":""}},{"id":3,"index":4,"parentId":2,"type":0,"option":5,"title":"Text","sequence":[],"isInLoop":true,"position":0,"parameters":{"history":1,"tabIndex":0,"useLoop":false,"xpath":"","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"clear":0,"newLine":0,"codeMode":2,"code":"return arguments[0].innerText","waitTime":0,"recordASField":1,"paraType":"text","emailConfig":{"host":"","port":465,"username":"","password":"","from":"","to":"","subject":"","content":""}}},{"id":4,"index":5,"parentId":2,"type":0,"option":5,"title":"Link","sequence":[],"isInLoop":true,"position":1,"parameters":{"history":1,"tabIndex":0,"useLoop":false,"xpath":"","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"clear":0,"newLine":1,"codeMode":2,"code":"return arguments[0].href","waitTime":0,"recordASField":1,"paraType":"text","emailConfig":{"host":"","port":465,"username":"","password":"","from":"","to":"","subject":"","content":""}}}]}
|
2
ExecuteStage/.vscode/launch.json
vendored
2
ExecuteStage/.vscode/launch.json
vendored
@ -12,7 +12,7 @@
|
||||
"justMyCode": false,
|
||||
// "args": ["--ids", "[7]", "--read_type", "remote", "--headless", "0"]
|
||||
// "args": ["--ids", "[9]", "--read_type", "remote", "--headless", "0", "--saved_file_name", "YOUTUBE"]
|
||||
"args": ["--ids", "[67]", "--headless", "0", "--user_data", "0", "--keyboard", "0",
|
||||
"args": ["--ids", "[13]", "--headless", "0", "--user_data", "0", "--keyboard", "0",
|
||||
"--read_type", "remote"]
|
||||
// "args": "--ids '[97]' --user_data 1 --server_address http://localhost:8074 --config_folder '/Users/naibo/Documents/EasySpider/ElectronJS/' --headless 0 --read_type remote --config_file_name config.json --saved_file_name"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user