Browse Source

修改爬虫群控代码逻辑

syh 5 years ago
parent
commit
7fd6593484

+ 19 - 8
module-crawler/src/main/java/cn/com/ctop/crawler/modules/core/util/AppiumUtil.java

@@ -408,15 +408,18 @@ public class AppiumUtil {
     }
     }
 
 
     public Boolean checkAdvertiser(AndroidDriver androidDriver, String advertiserName) {
     public Boolean checkAdvertiser(AndroidDriver androidDriver, String advertiserName) {
-        WebElement label = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/label");
-        String text = label.getText();
-        if (null != label && null != text && text.startsWith(advertiserName)) {
-            //表示广告筛选成功
-            return true;
-        } else {
-            backToMain(androidDriver);
-            return false;
+        Boolean check = false;
+        try {
+            WebElement label = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/label");
+            String text = label.getText();
+            if (null != label && null != text && text.startsWith(advertiserName)) {
+                //表示广告筛选成功
+                check = true;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
         }
         }
+        return check;
     }
     }
 
 
     public WebElement getElementByType(AndroidDriver androidDriver, String type, String typeInfo) {
     public WebElement getElementByType(AndroidDriver androidDriver, String type, String typeInfo) {
@@ -466,6 +469,8 @@ public class AppiumUtil {
                             } else if (appiumTaskItem.getTextEqualType().equals("start")) {
                             } else if (appiumTaskItem.getTextEqualType().equals("start")) {
                                 boolean check = checkAdvertiser(androidDriver, appiumTaskItem.getTextEqualKey());
                                 boolean check = checkAdvertiser(androidDriver, appiumTaskItem.getTextEqualKey());
                                 if (!check) {
                                 if (!check) {
+                                    backToMain(androidDriver);
+                                    Thread.sleep(1000L);
                                     return;
                                     return;
                                 }
                                 }
                             }
                             }
@@ -485,6 +490,11 @@ public class AppiumUtil {
                             }
                             }
                         }
                         }
                     } else {
                     } else {
+                        Thread.sleep(2000L);
+                        if (null != appiumTaskItem.getTextEqualType() && appiumTaskItem.getTextEqualType().equals("start")) {
+                            backToMain(androidDriver);
+                            return;
+                        }
                         //必须执行
                         //必须执行
                         if (appiumTaskItem.getIsMust() != null && appiumTaskItem.getIsMust() == 1) {
                         if (appiumTaskItem.getIsMust() != null && appiumTaskItem.getIsMust() == 1) {
                             if (appiumTaskItem.getLoopRate() != null && appiumTaskItem.getLoopRate() > 0) {
                             if (appiumTaskItem.getLoopRate() != null && appiumTaskItem.getLoopRate() > 0) {
@@ -509,6 +519,7 @@ public class AppiumUtil {
                     System.out.println("loop:" + isLoop);
                     System.out.println("loop:" + isLoop);
                     if (appiumTaskItem.getFindType() != null) {
                     if (appiumTaskItem.getFindType() != null) {
                         List<WebElement> list = getElementsByType(androidDriver, appiumTaskItem.getFindType(), appiumTaskItem.getFindKey());
                         List<WebElement> list = getElementsByType(androidDriver, appiumTaskItem.getFindType(), appiumTaskItem.getFindKey());
+                        System.out.println("元素数量:" + list.size());
                         if (list != null && list.size() > 0) {
                         if (list != null && list.size() > 0) {
                             for (WebElement element : list) {
                             for (WebElement element : list) {
                                 if (!isLoop) {
                                 if (!isLoop) {