wangkun 1 year ago
parent
commit
7d955ed4e6
1 changed files with 10 additions and 14 deletions
  1. 10 14
      shipinhao/shipinhao_search/shipinhao_search.py

+ 10 - 14
shipinhao/shipinhao_search/shipinhao_search.py

@@ -244,20 +244,16 @@ class ShipinhaoSearch:
     def check_to_webview(cls, log_type, crawler, driver: WebDriver):
         webviews = driver.contexts
         Common.logger(log_type, crawler).info(f"webviews:{webviews}")
-        for webview in webviews:
-            if webview == 'NATIVE_APP':
-                continue
-            driver.switch_to.context(webview)
-            time.sleep(1)
-            windowHandles = driver.window_handles
-            for handle in windowHandles:
-                driver.switch_to.window(handle)
-                time.sleep(1)
-                if len(driver.find_elements(By.XPATH, '//div[@class="unit"]')) != 0:
-                    Common.logger(log_type, crawler).info('切换 webview 成功')
-                    return "成功"
-                else:
-                    Common.logger(log_type, crawler).info("切换 webview 失败")
+        driver.switch_to.context(webviews[1])
+        time.sleep(1)
+        windowHandles = driver.window_handles
+        for handle in windowHandles:
+            driver.switch_to.window(handle)
+            if driver.find_element(By.XPATH, '//div[@class="unit"]'):
+                Common.logger(log_type, crawler).info('切换 webview 成功')
+                return "成功"
+            else:
+                Common.logger(log_type, crawler).info("切换 webview 失败")
 
     @classmethod
     def repeat_out_video_id(cls, log_type, crawler, out_video_id, env):