From 13b51ffdcc9db91bbcf03dd3fca84eb9b9e62ea0 Mon Sep 17 00:00:00 2001 From: naibo Date: Sat, 23 Dec 2023 12:36:35 +0800 Subject: [PATCH] =?UTF-8?q?JavaScript=E8=BE=93=E5=85=A5=E6=96=87=E5=AD=97?= =?UTF-8?q?=EF=BC=81=EF=BC=81=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ElectronJS/main.js | 22 ++++++++++++++++++++++ ElectronJS/src/taskGrid/FlowChart.html | 4 ++-- ElectronJS/src/taskGrid/FlowChart_CN.html | 4 ++-- ElectronJS/tasks/306.json | 1 + ElectronJS/tasks/307.json | 1 + ElectronJS/tasks/308.json | 1 + ExecuteStage/.vscode/launch.json | 2 +- ExecuteStage/easyspider_executestage.py | 7 ++++--- ExecuteStage/utils.py | 12 ++++++++++++ 9 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 ElectronJS/tasks/306.json create mode 100644 ElectronJS/tasks/307.json create mode 100644 ElectronJS/tasks/308.json diff --git a/ElectronJS/main.js b/ElectronJS/main.js index ef20f71..a3aaceb 100644 --- a/ElectronJS/main.js +++ b/ElectronJS/main.js @@ -741,6 +741,22 @@ async function beginInvoke(msg, ws) { keyInfo = keyInfo.replace(//gi, ""); enter = true; } + // 如果返回值中包含JS + if (/JS\(/i.test(keyInfo)) { + // 创建一个新的正则表达式来匹配JS语句 + let pattern = /JS\("(.+?)"\)/gi; + + // 找出所有的匹配项 + let matches = [...keyInfo.matchAll(pattern)]; + + // 处理每一个匹配项 + for (let match of matches) { + // 执行 JS 代码并等待结果 + let jsReplacedText = await execute_js(match[1], null, 0); + // 替换匹配到的 JS 语句 + keyInfo = keyInfo.replace(match[0], jsReplacedText.toString()); + } + } if (keyInfo.indexOf("Field(") >= 0 || keyInfo.indexOf("eval(") >= 0) { //两秒后通知浏览器 await new Promise((resolve) => setTimeout(resolve, 2000)); @@ -1184,6 +1200,12 @@ wss.on("connection", function (ws) { }); }); +wss.on("error", function (err) { + dialog.showErrorBox("端口占用错误 Port Occupied Error", "端口" + websocket_port + "被占用,大概率是重复打开了多个EasySpider程序导致,小概率是其他程序占用了此端口,请关闭所有已打开的EasySpider程序及其他占用此端口的程序,或重启系统后再次尝试打开软件。\nPort " + websocket_port + " is occupied, it is most likely that multiple EasySpider programs are opened repeatedly, or other programs occupy this port. Please close all opened EasySpider programs and other programs that occupy this port, or restart the system and try to open the software again."); + //退出程序 + app.quit(); +}); + console.log(process.platform); async function runBrowser(lang = "en", user_data_folder = "", mobile = false) { diff --git a/ElectronJS/src/taskGrid/FlowChart.html b/ElectronJS/src/taskGrid/FlowChart.html index a5302c5..94f54f6 100644 --- a/ElectronJS/src/taskGrid/FlowChart.html +++ b/ElectronJS/src/taskGrid/FlowChart.html @@ -349,8 +349,8 @@
- - + +
diff --git a/ElectronJS/src/taskGrid/FlowChart_CN.html b/ElectronJS/src/taskGrid/FlowChart_CN.html index 98388dc..260b9d6 100644 --- a/ElectronJS/src/taskGrid/FlowChart_CN.html +++ b/ElectronJS/src/taskGrid/FlowChart_CN.html @@ -349,8 +349,8 @@
- - + +
diff --git a/ElectronJS/tasks/306.json b/ElectronJS/tasks/306.json new file mode 100644 index 0000000..cfbb010 --- /dev/null +++ b/ElectronJS/tasks/306.json @@ -0,0 +1 @@ +{"id":306,"name":"XML Example","url":"https://www.chinanews.com.cn/rss/scroll-news.xml","links":"https://www.chinanews.com.cn/rss/scroll-news.xml","create_time":"2023-12-23 10:47:31","update_time":"2023-12-23 11:07:16","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.chinanews.com.cn/rss/scroll-news.xml","inputParameters":[{"id":0,"name":"urlList_0","nodeId":1,"nodeName":"打开网页","value":"https://www.chinanews.com.cn/rss/scroll-news.xml","desc":"要采集的网址列表,多行以\\n分开","type":"text","exampleValue":"https://www.chinanews.com.cn/rss/scroll-news.xml"}],"outputParameters":[{"id":0,"name":"自定义参数_1","desc":"","type":"text","recordASField":1,"exampleValue":"自定义值"}],"graph":[{"index":0,"id":0,"parentId":0,"type":-1,"option":0,"title":"root","sequence":[1,3],"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.chinanews.com.cn/rss/scroll-news.xml","links":"https://www.chinanews.com.cn/rss/scroll-news.xml","maxWaitTime":10,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"cookies":""}},{"id":3,"index":2,"parentId":2,"type":0,"option":3,"title":"提取数据","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":1,"params":[{"nodeType":0,"contentType":0,"relative":true,"name":"自定义参数_1","desc":"","iframe":false,"extractType":0,"relativeXPath":"","recordASField":1,"allXPaths":[],"exampleValues":[{"num":0,"value":"自定义值"}],"default":"","beforeJS":"1","beforeJSWaitTime":0,"JS":"","JSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"downloadPic":0,"paraType":"text","splitLine":0}]}},{"id":2,"index":3,"parentId":0,"type":1,"option":8,"title":"循环 - 不固定元素列表","sequence":[2],"isInLoop":false,"position":1,"parameters":{"history":1,"tabIndex":0,"useLoop":false,"xpath":"/rss/channel/item","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":"","textList":"","code":"","waitTime":0,"exitCount":0,"exitElement":"//body","historyWait":2,"breakMode":0,"breakCode":"","breakCodeWaitTime":0,"skipCount":0}},{"id":-1,"index":4,"parentId":0,"type":0,"option":3,"title":"提取数据","sequence":[],"isInLoop":false,"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,"params":[{"nodeType":0,"contentType":0,"relative":false,"name":"自定义参数_1","desc":"","iframe":false,"extractType":0,"relativeXPath":"/rss/channel/item","recordASField":1,"allXPaths":[],"exampleValues":[{"num":0,"value":"自定义值"}],"default":"","beforeJS":"","beforeJSWaitTime":0,"JS":"","JSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"downloadPic":0,"paraType":"text","splitLine":0}]}}]} \ No newline at end of file diff --git a/ElectronJS/tasks/307.json b/ElectronJS/tasks/307.json new file mode 100644 index 0000000..01ec19f --- /dev/null +++ b/ElectronJS/tasks/307.json @@ -0,0 +1 @@ +{"id":307,"name":"京东全球版-专业的综合网上购物商城","url":"https://www.jd.com","links":"https://www.jd.com","create_time":"2023-12-23 11:16:19","update_time":"2023-12-23 11:32:41","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"},{"id":1,"name":"inputText_1","nodeName":"输入文字","nodeId":2,"desc":"要输入的文本,如京东搜索框输入:电脑","type":"text","exampleValue":"Field[\"参数\"]TTTeval(\"self.a\")TTTJS(\"return new Date().getMonth()+1\")TTTJS(\"return new Date()\")","value":"Field[\"参数\"]TTTeval(\"self.a\")TTTJS(\"return new Date().getMonth()+1\")TTTJS(\"return new Date()\")"},{"id":2,"name":"loopText_2","nodeId":4,"nodeName":"循环输入文字","desc":"要输入的文本/网址,多行以\\n分开","type":"text","exampleValue":"JS(\"function getCurrentMonth() {var now = new Date(); var month = now.getMonth() + 1; return month;} return getCurrentMonth()\")/2023\nJS(\"function getCurrentMonth() {var now = new Date(); var month = now.getMonth() + 1; return month;} return getCurrentMonth()\")/2024\nJS(\"function getCurrentMonth() {var now = new Date(); var month = now.getMonth() + 1; return month;} return getCurrentMonth()\")/2025","value":"JS(\"function getCurrentMonth() {var now = new Date(); var month = now.getMonth() + 1; return month;} return getCurrentMonth()\")/2023\nJS(\"function getCurrentMonth() {var now = new Date(); var month = now.getMonth() + 1; return month;} return getCurrentMonth()\")/2024\nJS(\"function getCurrentMonth() {var now = new Date(); var month = now.getMonth() + 1; return month;} return getCurrentMonth()\")/2025"}],"outputParameters":[{"id":0,"name":"执行Python代码","desc":"自定义操作返回的数据","type":"text","recordASField":0,"exampleValue":""},{"id":1,"name":"参数","desc":"","type":"text","recordASField":1,"exampleValue":"手机"},{"id":2,"name":"参数2_链接地址","desc":"","type":"text","recordASField":1,"exampleValue":"https://shouji.jd.com/"}],"graph":[{"index":0,"id":0,"parentId":0,"type":-1,"option":0,"title":"root","sequence":[1,3,6,2,4],"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":4,"index":2,"parentId":0,"type":0,"option":4,"title":"输入文字","sequence":[],"isInLoop":false,"position":3,"parameters":{"history":4,"tabIndex":-1,"useLoop":false,"xpath":"//*[@id=\"key\"]","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"value":"Field[\"参数\"]TTTeval(\"self.a\")TTTJS(\"return new Date().getMonth()+1\")TTTJS(\"return new Date()\")","index":0,"allXPaths":["/html/body/div[4]/div[1]/div[2]/div[1]/input[1]","//input[contains(., '')]","id(\"key\")","//INPUT[@class='text']","/html/body/div[last()-6]/div/div[last()-2]/div/input"]}},{"id":2,"index":3,"parentId":0,"type":0,"option":5,"title":"执行Python代码","sequence":[],"isInLoop":false,"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":5,"code":"self.a = 222","waitTime":0,"recordASField":0,"paraType":"text","emailConfig":{"host":"","port":465,"username":"","password":"","from":"","to":"","subject":"","content":""}}},{"id":5,"index":4,"parentId":0,"type":1,"option":8,"title":"循环输入文字","sequence":[5],"isInLoop":false,"position":4,"parameters":{"history":3,"tabIndex":-1,"useLoop":false,"xpath":"//*[@id=\"key\"]","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"loopType":3,"pathList":"","textList":"JS(\"function getCurrentMonth() {var now = new Date(); var month = now.getMonth() + 1; return month;} return getCurrentMonth()\")/2023\nJS(\"function getCurrentMonth() {var now = new Date(); var month = now.getMonth() + 1; return month;} return getCurrentMonth()\")/2024\nJS(\"function getCurrentMonth() {var now = new Date(); var month = now.getMonth() + 1; return month;} return getCurrentMonth()\")/2025","code":"","waitTime":0,"exitCount":0,"exitElement":"//body","historyWait":2,"breakMode":0,"breakCode":"","breakCodeWaitTime":0,"skipCount":0,"allXPaths":["/html/body/div[4]/div[1]/div[2]/div[1]/input[1]","//input[contains(., '')]","id(\"key\")","//INPUT[@class='text']","/html/body/div[last()-6]/div/div[last()-2]/div/input"]}},{"id":7,"index":5,"parentId":5,"type":0,"option":4,"title":"输入文字","sequence":[],"isInLoop":true,"position":0,"parameters":{"history":3,"tabIndex":-1,"useLoop":true,"xpath":"//*[@id=\"key\"]","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"value":"result 1JS(\"return 22\")","index":0,"allXPaths":["/html/body/div[4]/div[1]/div[2]/div[1]/input[1]","//input[contains(., '')]","id(\"key\")","//INPUT[@class='text']","/html/body/div[last()-6]/div/div[last()-2]/div/input"]}},{"id":3,"index":6,"parentId":0,"type":1,"option":8,"title":"循环采集数据","sequence":[7],"isInLoop":false,"position":2,"parameters":{"history":3,"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[1]/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":["/html/body/div[5]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/a[1]","//a[contains(., '手机')]","/html/body/div[last()-5]/div/div[last()-4]/div/div[last()-2]/div/div/div/div[last()-1]/div[last()-12]/a[last()-1]"]}},{"id":6,"index":7,"parentId":3,"type":0,"option":3,"title":"提取数据","sequence":[],"isInLoop":true,"position":0,"parameters":{"history":3,"tabIndex":-1,"useLoop":false,"xpath":"","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"clear":0,"newLine":1,"params":[{"nodeType":1,"contentType":0,"relative":true,"name":"参数","desc":"","extractType":0,"relativeXPath":"","allXPaths":"","exampleValues":[{"num":0,"value":"手机"}],"unique_index":"tain0ppyd1rlqhi7699","iframe":false,"default":"","paraType":"text","recordASField":1,"beforeJS":"","beforeJSWaitTime":0,"JS":"","JSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"downloadPic":0,"splitLine":0},{"nodeType":2,"contentType":0,"relative":true,"name":"参数2_链接地址","desc":"","relativeXPath":"","allXPaths":"","exampleValues":[{"num":0,"value":"https://shouji.jd.com/"}],"unique_index":"tain0ppyd1rlqhi7699","iframe":false,"default":"","paraType":"text","recordASField":1,"beforeJS":"","beforeJSWaitTime":0,"JS":"","JSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"downloadPic":0,"splitLine":0}]}}]} \ No newline at end of file diff --git a/ElectronJS/tasks/308.json b/ElectronJS/tasks/308.json new file mode 100644 index 0000000..dd17203 --- /dev/null +++ b/ElectronJS/tasks/308.json @@ -0,0 +1 @@ +{"id":308,"name":"NUS Student Work Scheme","url":"https://inetapps.nus.edu.sg/nsws/app/login","links":"https://inetapps.nus.edu.sg/nsws/app/login","create_time":"2023-12-23 12:24:26","update_time":"2023-12-23 12:30:22","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://inetapps.nus.edu.sg/nsws/app/login","inputParameters":[{"id":0,"name":"urlList_0","nodeId":1,"nodeName":"打开网页","value":"https://inetapps.nus.edu.sg/nsws/app/login","desc":"要采集的网址列表,多行以\\n分开","type":"text","exampleValue":"https://inetapps.nus.edu.sg/nsws/app/login"},{"id":1,"name":"inputText_1","nodeName":"输入文字","nodeId":3,"desc":"要输入的文本,如京东搜索框输入:电脑","type":"text","exampleValue":"e0546263@u.nus.edu","value":"e0546263@u.nus.edu"},{"id":2,"name":"inputText_2","nodeName":"输入文字","nodeId":4,"desc":"要输入的文本,如京东搜索框输入:电脑","type":"text","exampleValue":"Qw982311099.","value":"Qw982311099."},{"id":3,"name":"loopText_3","nodeId":11,"nodeName":"循环输入文字","desc":"要输入的文本/网址,多行以\\n分开","type":"text","exampleValue":"01/JS(\"return new Date().getMonth()+1\")/2023\n08/JS(\"return new Date().getMonth()+1\")/2023\n15/JS(\"return new Date().getMonth()+1\")/2023\n22/JS(\"return new Date().getMonth()+1\")/2023","value":"01/JS(\"return new Date().getMonth()+1\")/2023\n08/JS(\"return new Date().getMonth()+1\")/2023\n15/JS(\"return new Date().getMonth()+1\")/2023\n22/JS(\"return new Date().getMonth()+1\")/2023"},{"id":4,"name":"inputText_4","nodeName":"输入文字","nodeId":13,"desc":"要输入的文本,如京东搜索框输入:电脑","type":"text","exampleValue":"18","value":"18"},{"id":5,"name":"inputText_5","nodeName":"输入文字","nodeId":14,"desc":"要输入的文本,如京东搜索框输入:电脑","type":"text","exampleValue":"45","value":"45"}],"outputParameters":[],"graph":[{"index":0,"id":0,"parentId":0,"type":-1,"option":0,"title":"root","sequence":[1,2,3,4,5,7,8,11],"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://inetapps.nus.edu.sg/nsws/app/login","links":"https://inetapps.nus.edu.sg/nsws/app/login","maxWaitTime":10,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"cookies":""}},{"id":2,"index":2,"parentId":0,"type":0,"option":2,"title":"点击NUS St...","sequence":[],"isInLoop":false,"position":1,"parameters":{"history":4,"tabIndex":-1,"useLoop":false,"xpath":"//*[contains(@class, \"gx-2\")]/div[1]/div[1]/a[1]","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":0,"maxWaitTime":10,"params":[],"alertHandleType":0,"allXPaths":["/html/body/app-root[1]/app-login-safe[1]/div[1]/div[1]/div[2]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/a[1]","//a[contains(., 'NUS Studen')]","//A[@class='btn btn-primary text-white']","/html/body/app-root/app-login-safe/div/div/div/div/div[last()-1]/div/div/div/div/a[last()-1]"]}},{"id":3,"index":3,"parentId":0,"type":0,"option":4,"title":"输入文字","sequence":[],"isInLoop":false,"position":2,"parameters":{"history":5,"tabIndex":-1,"useLoop":false,"xpath":"//*[@id=\"userNameInput\"]","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"value":"e0546263@u.nus.edu","index":0,"allXPaths":["/html/body/div[2]/div[2]/div[1]/main[1]/div[1]/div[1]/div[1]/form[1]/div[2]/div[1]/input[1]","//input[contains(., '')]","id(\"userNameInput\")","//INPUT[@class='text fullWidth']","//INPUT[@name='UserName']","/html/body/div[last()-3]/div/div/main/div/div/div/form/div/div[last()-3]/input"]}},{"id":4,"index":4,"parentId":0,"type":0,"option":4,"title":"输入文字","sequence":[],"isInLoop":false,"position":3,"parameters":{"history":5,"tabIndex":-1,"useLoop":false,"xpath":"//*[@id=\"passwordInput\"]","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"value":"Qw982311099.","index":0,"allXPaths":["/html/body/div[2]/div[2]/div[1]/main[1]/div[1]/div[1]/div[1]/form[1]/div[2]/div[2]/input[1]","//input[contains(., '')]","id(\"passwordInput\")","//INPUT[@class='text fullWidth']","//INPUT[@name='Password']","/html/body/div[last()-3]/div/div/main/div/div/div/form/div/div[last()-2]/input"]}},{"id":5,"index":5,"parentId":0,"type":0,"option":2,"title":"点击Sign i...","sequence":[],"isInLoop":false,"position":4,"parameters":{"history":5,"tabIndex":-1,"useLoop":false,"xpath":"//*[@id=\"submitButton\"]","iframe":false,"wait":20,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"clickWay":0,"newTab":0,"maxWaitTime":10,"params":[],"alertHandleType":0,"allXPaths":["/html/body/div[2]/div[2]/div[1]/main[1]/div[1]/div[1]/div[1]/form[1]/div[2]/div[4]/span[1]","//span[contains(., 'Sign in')]","id(\"submitButton\")","//SPAN[@class='submit']","/html/body/div[last()-3]/div/div/main/div/div/div/form/div/div/span"]}},{"id":-1,"index":6,"parentId":0,"type":0,"option":3,"title":"提取数据","sequence":[],"isInLoop":false,"position":5,"parameters":{"history":7,"tabIndex":-1,"useLoop":false,"xpath":"","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"clear":0,"newLine":1,"params":[{"nodeType":4,"contentType":0,"relative":false,"name":"参数1_图片地址","desc":"","extractType":0,"relativeXPath":"/html/body/app-root[1]/div[1]/div[1]/img[1]","allXPaths":["/html/body/app-root[1]/div[1]/div[1]/img[1]","//img[contains(., '')]","/html/body/app-root/div/div/img"],"exampleValues":[{"num":0,"value":"assets/images/Spinner.gif"}],"unique_index":"3ocguj5rafhlqhk493w","iframe":false,"default":"","paraType":"text","recordASField":1,"beforeJS":"","beforeJSWaitTime":0,"JS":"","JSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"downloadPic":0,"splitLine":0}]}},{"id":6,"index":7,"parentId":0,"type":0,"option":2,"title":"点击1\nALLO...","sequence":[],"isInLoop":false,"position":5,"parameters":{"history":7,"tabIndex":-1,"useLoop":false,"xpath":"//*[contains(@class, \"nsws-content\")]/app-student-dashboard[1]/div[1]/div[3]/div[3]","iframe":false,"wait":20,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"clickWay":0,"newTab":0,"maxWaitTime":10,"params":[],"alertHandleType":0,"allXPaths":["/html/body/app-root[1]/app-student[1]/div[1]/div[1]/app-student-dashboard[1]/div[1]/div[3]/div[3]","//div[contains(., '1ALLOCATED')]","//DIV[@class='dashboard-item']","/html/body/app-root/app-student/div/div[last()-1]/app-student-dashboard/div/div[last()-3]/div"]}},{"id":7,"index":8,"parentId":0,"type":0,"option":2,"title":"点击Server...","sequence":[],"isInLoop":false,"position":6,"parameters":{"history":8,"tabIndex":-1,"useLoop":false,"xpath":"//*[contains(@class, \"nsws-table\")]/tbody[1]/tr[1]/td[2]","iframe":false,"wait":5,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"clickWay":0,"newTab":0,"maxWaitTime":10,"params":[],"alertHandleType":0,"allXPaths":["/html/body/app-root[1]/app-student[1]/div[1]/div[1]/app-manage-jobs[1]/app-student-job-list[1]/div[1]/div[1]/div[1]/div[1]/tabset[1]/div[1]/tab[1]/app-nsws-data-table-v2[1]/div[1]/table[1]/tbody[1]/tr[1]/td[2]","//td[contains(., 'Server Adm')]","//TD[@class='text-left data-table-row-clickable']","/html/body/app-root/app-student/div/div[last()-1]/app-manage-jobs/app-student-job-list/div/div/div/div/tabset/div/tab[last()-1]/app-nsws-data-table-v2/div[last()-2]/table/tbody/tr/td[last()-9]"]}},{"id":-1,"index":9,"parentId":0,"type":1,"option":8,"title":"循环点击:ADD NEW","sequence":[],"isInLoop":false,"position":8,"parameters":{"history":9,"tabIndex":-1,"useLoop":false,"xpath":"","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"loopType":0,"pathList":"","code":"","waitTime":0,"exitCount":0,"exitElement":"//body","historyWait":2,"breakMode":0,"breakCode":"","breakCodeWaitTime":0,"skipCount":0,"allXPaths":["/html/body/app-root[1]/app-student[1]/div[1]/div[1]/app-manage-jobs[1]/app-student-timesheet-hourly[1]/div[1]/div[1]/div[1]/button[1]","//button[contains(., 'ADD NEW')]","//BUTTON[@class='btn btn-primary']","/html/body/app-root/app-student/div/div[last()-1]/app-manage-jobs/app-student-timesheet-hourly/div/div[last()-1]/div/button"]}},{"id":9,"index":10,"parentId":8,"type":0,"option":2,"title":"点击ADD NE...","sequence":[],"isInLoop":true,"position":0,"parameters":{"history":9,"tabIndex":-1,"useLoop":false,"xpath":"//*[contains(@class, \"nsws-content\")]/app-manage-jobs[1]/app-student-timesheet-hourly[1]/div[1]/div[1]/div[1]/button[1]","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":0,"maxWaitTime":10,"params":[],"alertHandleType":0,"allXPaths":["/html/body/app-root[1]/app-student[1]/div[1]/div[1]/app-manage-jobs[1]/app-student-timesheet-hourly[1]/div[1]/div[1]/div[1]/button[1]","//button[contains(., 'ADD NEW')]","//BUTTON[@class='btn btn-primary']","/html/body/app-root/app-student/div/div[last()-1]/app-manage-jobs/app-student-timesheet-hourly/div/div[last()-1]/div/button"]}},{"id":8,"index":11,"parentId":0,"type":1,"option":8,"title":"循环输入文字","sequence":[10,12,13,14,15],"isInLoop":false,"position":7,"parameters":{"history":10,"tabIndex":-1,"useLoop":false,"xpath":"//*[@id=\"job_date\"]","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"loopType":3,"pathList":"","textList":"01/JS(\"return new Date().getMonth()+1\")/2023\n08/JS(\"return new Date().getMonth()+1\")/2023\n15/JS(\"return new Date().getMonth()+1\")/2023\n22/JS(\"return new Date().getMonth()+1\")/2023","code":"","waitTime":0,"exitCount":0,"exitElement":"//body","historyWait":2,"breakMode":0,"breakCode":"","breakCodeWaitTime":0,"skipCount":0,"allXPaths":["/html/body/app-root[1]/app-student[1]/div[1]/div[1]/app-manage-jobs[1]/app-student-timesheet-form[1]/div[1]/form[1]/div[1]/div[1]/div[1]/div[1]/input[1]","//input[contains(., '')]","id(\"job_date\")","//INPUT[@class='form-control ng-untouched ng-pristine ng-valid']","/html/body/app-root/app-student/div/div[last()-1]/app-manage-jobs/app-student-timesheet-form/div/form/div[last()-2]/div/div/div/input"]}},{"id":10,"index":12,"parentId":8,"type":0,"option":4,"title":"输入文字","sequence":[],"isInLoop":true,"position":1,"parameters":{"history":10,"tabIndex":-1,"useLoop":true,"xpath":"//*[@id=\"job_date\"]","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"value":"01/12/2023","index":0,"allXPaths":["/html/body/app-root[1]/app-student[1]/div[1]/div[1]/app-manage-jobs[1]/app-student-timesheet-form[1]/div[1]/form[1]/div[1]/div[1]/div[1]/div[1]/input[1]","//input[contains(., '')]","id(\"job_date\")","//INPUT[@class='form-control ng-untouched ng-pristine ng-valid']","/html/body/app-root/app-student/div/div[last()-1]/app-manage-jobs/app-student-timesheet-form/div/form/div[last()-2]/div/div/div/input"]}},{"id":11,"index":13,"parentId":8,"type":0,"option":4,"title":"输入文字","sequence":[],"isInLoop":true,"position":2,"parameters":{"history":11,"tabIndex":-1,"useLoop":false,"xpath":"//*[contains(@class, \"timesheet-payable\")]/div[3]/div[1]/app-nsws-timepicker[1]/table[1]/tr[2]/td[1]/input[1]","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"value":"18","index":0,"allXPaths":["/html/body/app-root[1]/app-student[1]/div[1]/div[1]/app-manage-jobs[1]/app-student-timesheet-form[1]/div[1]/form[1]/div[2]/div[1]/div[3]/div[1]/app-nsws-timepicker[1]/table[1]/tr[2]/td[1]/input[1]","//input[contains(., '')]","//INPUT[@class='form-control ng-untouched ng-pristine ng-valid']","/html/body/app-root/app-student/div/div[last()-1]/app-manage-jobs/app-student-timesheet-form/div/form/div[last()-1]/div[last()-2]/div[last()-2]/div/app-nsws-timepicker/table/tr[last()-1]/td[last()-2]/input"]}},{"id":12,"index":14,"parentId":8,"type":0,"option":4,"title":"输入文字","sequence":[],"isInLoop":true,"position":3,"parameters":{"history":11,"tabIndex":-1,"useLoop":false,"xpath":"//*[contains(@class, \"timesheet-payable\")]/div[3]/div[1]/app-nsws-timepicker[1]/table[1]/tr[2]/td[3]/input[1]","iframe":false,"wait":0,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"value":"45","index":0,"allXPaths":["/html/body/app-root[1]/app-student[1]/div[1]/div[1]/app-manage-jobs[1]/app-student-timesheet-form[1]/div[1]/form[1]/div[2]/div[1]/div[3]/div[1]/app-nsws-timepicker[1]/table[1]/tr[2]/td[3]/input[1]","//input[contains(., '')]","//INPUT[@class='form-control ng-untouched ng-pristine ng-valid']","/html/body/app-root/app-student/div/div[last()-1]/app-manage-jobs/app-student-timesheet-form/div/form/div[last()-1]/div[last()-2]/div[last()-2]/div/app-nsws-timepicker/table/tr[last()-1]/td/input"]}},{"id":13,"index":15,"parentId":8,"type":0,"option":2,"title":"点击SAVE A...","sequence":[],"isInLoop":true,"position":4,"parameters":{"history":11,"tabIndex":-1,"useLoop":false,"xpath":"//*[contains(@class, \"nsws-action-buttons\")]/button[1]","iframe":false,"wait":5,"waitType":0,"beforeJS":"","beforeJSWaitTime":0,"afterJS":"","afterJSWaitTime":0,"waitElement":"","waitElementTime":10,"waitElementIframeIndex":0,"scrollType":0,"scrollCount":1,"scrollWaitTime":1,"clickWay":0,"newTab":0,"maxWaitTime":10,"params":[],"alertHandleType":0,"allXPaths":["/html/body/app-root[1]/app-student[1]/div[1]/div[1]/app-manage-jobs[1]/app-student-timesheet-form[1]/div[1]/form[1]/div[3]/button[1]","//button[contains(., 'SAVE AS DR')]","//BUTTON[@class='btn btn-primary']","/html/body/app-root/app-student/div/div[last()-1]/app-manage-jobs/app-student-timesheet-form/div/form/div/button[last()-1]"]}}]} \ No newline at end of file diff --git a/ExecuteStage/.vscode/launch.json b/ExecuteStage/.vscode/launch.json index d060307..d70be9a 100644 --- a/ExecuteStage/.vscode/launch.json +++ b/ExecuteStage/.vscode/launch.json @@ -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", "[11]", "--headless", "0", "--user_data", "0", "--keyboard", "0", + "args": ["--ids", "[60]", "--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" } diff --git a/ExecuteStage/easyspider_executestage.py b/ExecuteStage/easyspider_executestage.py index 02a3a5a..1db3930 100644 --- a/ExecuteStage/easyspider_executestage.py +++ b/ExecuteStage/easyspider_executestage.py @@ -1588,10 +1588,11 @@ class BrowserThread(Thread): else: value = param["value"] # 将value中的Field[""]替换为outputParameters中的键值 - pattern = r'Field\["([^"]+)"\]' + # pattern = r'Field\["([^"]+)"\]' try: - replaced_text = re.sub( - pattern, lambda match: self.outputParameters.get(match.group(1), ''), value) + # replaced_text = re.sub( + # pattern, lambda match: self.outputParameters.get(match.group(1), ''), value) + replaced_text = replace_field_values(value, self.outputParameters, self) replaced_text = re.sub( '', '', replaced_text, flags=re.IGNORECASE) except: diff --git a/ExecuteStage/utils.py b/ExecuteStage/utils.py index 528df1c..620526e 100644 --- a/ExecuteStage/utils.py +++ b/ExecuteStage/utils.py @@ -308,6 +308,18 @@ def replace_field_values(orginal_text, outputParameters, browser=None): eval_replaced_text = str(eval(match.group(1))) # 替换eval语句 replaced_text = replaced_text.replace(match.group(0), eval_replaced_text) + if re.search(r'JS\(', replaced_text, re.IGNORECASE): # 如果返回值中包含JS + replaced_text = replaced_text.replace("self.", "browser.") + pattern = re.compile(r'(?i)JS\("(.+?)"\)') + # 循环替换所有匹配到的JS语句 + while True: + match = pattern.search(replaced_text) + if not match: + break + # 执行JS并将其结果转换为字符串形式 + JS_replaced_text = str(browser.browser.execute_script(match.group(1))) + # 替换JS语句 + replaced_text = replaced_text.replace(match.group(0), JS_replaced_text) except Exception as e: print("eval替换失败,请检查eval语句是否正确。| Failed to replace eval, please check if the eval statement is correct.") print(e)