瀏覽代碼

Skip Loop

naibo 1 年之前
父節點
當前提交
69f0c1128c

+ 1 - 1
ElectronJS/config.json

@@ -1 +1 @@
-{"webserver_address":"http://localhost","webserver_port":8074,"user_data_folder":"","debug":false,"copyright":1,"sys_version":"x64","mysql_config_path":"./mysql_config.json","absolute_user_data_folder":"/Users/naibo/Documents/EasySpider/ElectronJS/user_data"}
+{"webserver_address":"http://localhost","webserver_port":8074,"user_data_folder":"./user_data","debug":false,"copyright":1,"sys_version":"x64","mysql_config_path":"./mysql_config.json","absolute_user_data_folder":"D:\\Documents\\Projects\\EasySpider\\ElectronJS\\user_data"}

+ 5 - 2
ElectronJS/main.js

@@ -15,6 +15,7 @@ const util = require('util');
 
 let config = fs.readFileSync(path.join(task_server.getDir(), `config.json`), 'utf8');
 config = JSON.parse(config);
+let config_context = JSON.parse(fs.readFileSync(path.join(task_server.getDir(), `config.json`), 'utf8')); //仅在当前进程中使用,不会写入文件
 
 if (config.debug) {
     let logPath = 'info.log'
@@ -302,7 +303,7 @@ async function beginInvoke(msg, ws) {
         // It will prompt an accessibility permission request dialog, if needed.
         if (process.platform != "linux" && process.platform != "darwin") {
             // 非用户信息模式下,设置窗口位置
-            if (config.user_data_folder == null || config.user_data_folder == undefined || config.user_data_folder == "") {
+            if (config_context.user_data_folder == null || config_context.user_data_folder == undefined || config_context.user_data_folder == "") {
                 const {windowManager} = require("node-window-manager");
                 const window = windowManager.getActiveWindow();
                 console.log(window);
@@ -815,6 +816,7 @@ function send_message_to_browser(message) {
 
 const WebSocket = require('ws');
 const {all} = require("express/lib/application");
+const {copy} = require("selenium-webdriver/io");
 let wss = new WebSocket.Server({port: websocket_port});
 wss.on('connection', function (ws) {
     ws.on('message', async function (message, isBinary) {
@@ -922,9 +924,10 @@ async function runBrowser(lang = "en", user_data_folder = '', mobile = false) {
         console.log(dir);
         options.addArguments("--user-data-dir=" + dir);
         config.user_data_folder = user_data_folder;
+        config_context.user_data_folder = user_data_folder;
         fs.writeFileSync(path.join(task_server.getDir(), "config.json"), JSON.stringify(config));
     } else {
-        config.user_data_folder = "";
+        config_context.user_data_folder = "";
     }
     if (mobile) {
         const mobileEmulation = {

+ 3 - 3
ElectronJS/server.js

@@ -368,9 +368,9 @@ exports.start = function(port = 8074) {
                 res.write(eid.toString(), 'utf8');
                 res.end();
             } else if(pathName == "/getConfig"){
-                let config = fs.readFileSync(path.join(getDir(), `config.json`), 'utf8');
-                config = JSON.parse(config);
-                res.write(JSON.stringify(config));
+                let config_file = fs.readFileSync(path.join(getDir(), `config.json`), 'utf8');
+                config_file = JSON.parse(config_file);
+                res.write(JSON.stringify(config_file));
                 res.end();
             } else if(pathName == "/setUserDataFolder"){
                 let config = fs.readFileSync(path.join(getDir(), `config.json`), 'utf8');

+ 7 - 3
ElectronJS/src/taskGrid/FlowChart.html

@@ -29,9 +29,7 @@
             <ol class="breadcrumb" style="padding-left:23px;padding-bottom: 0;margin-bottom:0;background-color: white">
                 <li @click="gotoHome" class="breadcrumb-item"><a href="#">{{"Home~首页" | lang}}</a></li>
                 <li @click="gotoInfo" aria-current="page" class="breadcrumb-item" style="color: black"><a href="#">{{"Task Information~任务信息" | lang}}</a></li>
-                <li aria-current="page" class="breadcrumb-item active" style="color: black">{{"Task Modification~任务流程修改"
-                    | lang}}
-                </li>
+                <li aria-current="page" class="breadcrumb-item active" style="color: black">{{"Task Flow~任务流程" | lang}}</li>
             </ol>
         </nav>
     </div>
@@ -586,6 +584,12 @@ If the expression returns a value greater than 0 or evaluates to True, the loop
                             </div>
                         </div>
                     </div>
+
+                    <div v-if="parseInt(loopType) < 5 && parseInt(loopType) > 0">
+                        <label>Skip the first few loops (enter 2 to skip the first 2 loops):</label>
+                        <input spellcheck="false" onkeydown="inputDelete(event)" required class="form-control" type="number" v-model.number='nowNode["parameters"]["skipCount"]'></input>
+                    </div>
+
                     <label>Waiting time in seconds after a history record rollback: </label>
                     <input spellcheck=false onkeydown="inputDelete(event)" required type="number" class="form-control" v-model.number='list.nl[index.nowNodeIndex]["parameters"]["historyWait"]'></input>
                     <label>After executed, whether scroll down:</label>

+ 9 - 4
ElectronJS/src/taskGrid/FlowChart_CN.html

@@ -29,9 +29,7 @@
             <ol class="breadcrumb" style="padding-left:23px;padding-bottom: 0;margin-bottom:0;background-color: white">
                 <li @click="gotoHome" class="breadcrumb-item"><a href="#">{{"Home~首页" | lang}}</a></li>
                 <li @click="gotoInfo" aria-current="page" class="breadcrumb-item" style="color: black"><a href="#">{{"Task Information~任务信息" | lang}}</a></li>
-                <li aria-current="page" class="breadcrumb-item active" style="color: black">{{"Task Modification~任务流程修改"
-                    | lang}}
-                </li>
+                <li aria-current="page" class="breadcrumb-item active" style="color: black">{{"Task Flow~任务流程" | lang}}</li>
             </ol>
         </nav>
     </div>
@@ -146,7 +144,7 @@
                         <p><input spellcheck=false onkeydown="inputDelete(event)" type="checkbox" v-model='useLoop'></input>使用相对循环内的XPath定位到的元素</p>
                     </div>
                     <div>
-                        <label>XPath(或者用point(10,10)表示点击网页坐标位置(10, 10)以用来点击空白区域推出弹窗对话框等): <span style="font-size: 30px!important;" title="相对XPATH写法:以/开头,如循环项XPATH为/html/body/div[1],您的输入为/*[@id='tab-customer'],则最终寻址的xpath为:/html/body/div[1]/*[@id='tab-customer']">☺</span></label>
+                        <label>XPath(或者用point(10,10)表示点击网页坐标位置(10, 10)以用来点击空白区域推出弹窗对话框文本列表等): <span style="font-size: 30px!important;" title="相对XPATH写法:以/开头,如循环项XPATH为/html/body/div[1],您的输入为/*[@id='tab-customer'],则最终寻址的xpath为:/html/body/div[1]/*[@id='tab-customer']">☺</span></label>
                         <textarea spellcheck=false onkeydown="inputDelete(event)" class="form-control" rows="2" v-model='nowNode["parameters"]["xpath"]'></textarea>
                         <p><button type="button" data-toggle="modal" data-target="#myModal_XPath" @click="changeXPaths(nowNode['parameters']['allXPaths'])" class="btn btn-primary" style="margin-top: 10px">点此查看其他等价的XPath</button></p>
                     </div>
@@ -586,8 +584,15 @@ print(emotlib.emoji()) # 使用其中的函数。
                             </div>
                         </div>
                     </div>
+
+                    <div v-if="parseInt(loopType) < 5 && parseInt(loopType) > 0">
+                        <label>跳过前几次循环(如要跳过前2个循环则填写2):</label>
+                        <input spellcheck=false onkeydown="inputDelete(event)" required class="form-control" type="number" v-model.number='nowNode["parameters"]["skipCount"]'></input>
+                    </div>
+
                     <label><b>历史记录回退后</b>等待秒数:</label>
                     <input spellcheck=false onkeydown="inputDelete(event)" required type="number" class="form-control" v-model.number='list.nl[index.nowNodeIndex]["parameters"]["historyWait"]'></input>
+
                     <label>执行完是否向下滚动:</label>
                     <select v-model='nowNode["parameters"]["scrollType"]' class="form-control">
                         <option :value = 0>不滚动</option>

+ 1 - 0
ElectronJS/src/taskGrid/logic.js

@@ -316,6 +316,7 @@ function addParameters(t) {
         t["parameters"]["breakMode"] = 0; //break类型,0代表JS,2代表系统命令
         t["parameters"]["breakCode"] = ""; //break条件
         t["parameters"]["breakCodeWaitTime"] = 0; //break条件等待时间
+        t["parameters"]["skipCount"] = 0; //跳过前多少次循环
     } else if (t.option == 9) { //条件
         t["title"] = LANG("判断条件 - 从左往右依次判断", "Judgment Condition - Judge from Left to Right");
     } else if (t.option == 10) { //条件分支

文件差異過大導致無法顯示
+ 0 - 0
ElectronJS/tasks/295.json


文件差異過大導致無法顯示
+ 0 - 0
ElectronJS/tasks/297.json


文件差異過大導致無法顯示
+ 0 - 0
ElectronJS/tasks/298.json


+ 1 - 1
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", "[62]", "--headless", "0", "--user_data", "0", "--keyboard", "0",
+            "args": ["--ids", "[77]", "--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"
         }

+ 36 - 8
ExecuteStage/easyspider_executestage.py

@@ -333,6 +333,10 @@ class BrowserThread(Thread):
                 except:
                     node["parameters"]["exitElement"] = "//body"
                 node["parameters"]["quickExtractable"] = False # 是否可以快速提取
+                try:
+                    skipCount = node["parameters"]["skipCount"]
+                except:
+                    node["parameters"]["skipCount"] = 0
                 # 如果(不)固定元素列表循环中只有一个提取数据操作,且提取数据操作的提取内容为元素截图,那么可以快速提取
                 if len(node["sequence"]) == 1 and self.procedure[node["sequence"][0]]["option"] == 3 and (int(node["parameters"]["loopType"]) == 1 or int(node["parameters"]["loopType"]) == 2):
                     try:
@@ -347,6 +351,8 @@ class BrowserThread(Thread):
                         node["parameters"]["quickExtractable"] = False # 如果是iframe,那么不可以快速提取
                     else:
                         node["parameters"]["quickExtractable"] = True # 先假设可以快速提取
+                    if node["parameters"]["skipCount"] > 0:
+                        node["parameters"]["quickExtractable"] = False # 如果有跳过的元素,那么不可以快速提取
                     for param in params:
                         optimizable = detect_optimizable(param, ignoreWaitElement=False, waitElement=waitElement)
                         try:
@@ -1210,7 +1216,13 @@ class BrowserThread(Thread):
                                        xpath)
                     self.print_and_log("找不到循环元素:", xpath)
                 index = 0
+                skipCount = node["parameters"]["skipCount"]
                 while index < len(elements):
+                    if index < skipCount:
+                        index += 1
+                        self.print_and_log("跳过第" + str(index) + "个元素")
+                        self.print_and_log("Skip the " + str(index) + "th element")
+                        continue
                     try:
                         element = elements[index]
                         element_text = element.text
@@ -1266,7 +1278,13 @@ class BrowserThread(Thread):
             paths = node["parameters"]["pathList"].split("\n")
             # for path in node["parameters"]["pathList"].split("\n"):
             index = 0
+            skipCount = node["parameters"]["skipCount"]
             while index < len(paths):
+                if index < skipCount:
+                    index += 1
+                    self.print_and_log("跳过第" + str(index) + "个元素")
+                    self.print_and_log("Skip the " + str(index) + "th element")
+                    continue
                 path = paths[index]
                 try:
                     path = replace_field_values(
@@ -1322,7 +1340,14 @@ class BrowserThread(Thread):
             if len(textList) == 1:  # 如果固定文本列表只有一行,现在就可以替换变量
                 textList = replace_field_values(
                     node["parameters"]["textList"], self.outputParameters, self).split("\n")
+            skipCount = node["parameters"]["skipCount"]
+            index = 0
             for text in textList:
+                if index < skipCount:
+                    index += 1
+                    self.print_and_log("跳过第" + str(index) + "个文本")
+                    self.print_and_log("Skip the " + str(index) + "th text")
+                    continue
                 text = replace_field_values(text, self.outputParameters, self)
                 # self.recordLog("当前循环文本|Current loop text:", text)
                 for i in node["sequence"]:  # 挨个执行操作
@@ -1348,11 +1373,14 @@ class BrowserThread(Thread):
             if len(urlList) == 1:  # 如果固定网址列表只有一行,现在就可以替换变量
                 urlList = replace_field_values(
                     node["parameters"]["textList"], self.outputParameters, self).split("\n")
-            # urlList = []
-            # for url in tempList:
-            #     if url != "":
-            #         urlList.append(url)
+            skipCount = node["parameters"]["skipCount"]
+            index = 0
             for url in urlList:
+                if index < skipCount:
+                    index += 1
+                    self.print_and_log("跳过第" + str(index) + "个网址")
+                    self.print_and_log("Skip the " + str(index) + "th url")
+                    continue
                 url = replace_field_values(url, self.outputParameters, self)
                 # self.recordLog("当前循环网址|Current loop url:", url)
                 for i in node["sequence"]:
@@ -1400,7 +1428,7 @@ class BrowserThread(Thread):
         self.history["handle"] = self.browser.current_window_handle
         self.scrollDown(node["parameters"])
 
-    # 打开网页事件
+    # 打开网页操作
     def openPage(self, param, loopValue):
         time.sleep(1)  # 打开网页后强行等待至少1秒
         if len(self.browser.window_handles) > 1:
@@ -1465,7 +1493,7 @@ class BrowserThread(Thread):
             self.history["index"] = 0
         self.scrollDown(param)  # 控制屏幕向下滚动
 
-    # 键盘输入事件
+    # 键盘输入操作
     def inputInfo(self, param, loopValue):
         time.sleep(0.1)  # 输入之前等待0.1秒
         try:
@@ -1517,7 +1545,7 @@ class BrowserThread(Thread):
                                xpath + ", please try to set the wait time before executing this operation")
             self.print_and_log("找不到输入框元素:" + xpath + ",请尝试在执行此操作前设置等待时间")
 
-    # 点击元素事件
+    # 点击元素操作
     def clickElement(self, param, loopElement=None, clickPath="", index=0):
         try:
             maxWaitTime = int(param["maxWaitTime"])
@@ -1853,7 +1881,7 @@ class BrowserThread(Thread):
             self.outputParameters[key] = ""
         self.recordLog("清空输出参数|Clear output parameters")
 
-    # 提取数据事件
+    # 提取数据操作
     def getData(self, param, loopElement, isInLoop=True, parentPath="", index=0):
         parentPath = replace_field_values(
             parentPath, self.outputParameters, self)

部分文件因文件數量過多而無法顯示