wangkun 1 year ago
parent
commit
d5e47ad602
1 changed files with 11 additions and 10 deletions
  1. 11 10
      shipinhao/shipinhao_search/shipinhao_search.py

+ 11 - 10
shipinhao/shipinhao_search/shipinhao_search.py

@@ -243,17 +243,18 @@ class ShipinhaoSearch:
     def check_to_webview(cls, log_type, crawler, driver: WebDriver):
         webviews = driver.contexts
         Common.logger(log_type, crawler).info(f"webviews:{webviews}")
-        driver.switch_to.context(webviews[1])
-        time.sleep(1)
-        windowHandles = driver.window_handles
-        for handle in windowHandles:
-            driver.switch_to.window(handle)
+        for webview in webviews:
+            driver.switch_to.context(webview)
             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 失败")
+            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 失败")
 
     @classmethod
     def repeat_out_video_id(cls, log_type, crawler, out_video_id, env):