wangkun 1 tahun lalu
induk
melakukan
68fcde420f
1 mengubah file dengan 6 tambahan dan 4 penghapusan
  1. 6 4
      shipinhao/shipinhao_search/shipinhao_search.py

+ 6 - 4
shipinhao/shipinhao_search/shipinhao_search.py

@@ -245,15 +245,17 @@ class ShipinhaoSearch:
         webviews = driver.contexts
         Common.logger(log_type, crawler).info(f"webviews:{webviews}")
         driver.switch_to.context(webviews[1])
+        Common.logger(log_type, crawler).info(driver.current_context)
         time.sleep(1)
         windowHandles = driver.window_handles
         for handle in windowHandles:
-            driver.switch_to.window(handle)
-            time.sleep(1)
-            if driver.find_element(By.XPATH, '//div[@class="unit"]'):
+            try:
+                driver.switch_to.window(handle)
+                time.sleep(1)
+                driver.find_element(By.XPATH, '//div[@class="unit"]')
                 Common.logger(log_type, crawler).info('切换 webview 成功')
                 return "成功"
-            else:
+            except Exception:
                 Common.logger(log_type, crawler).info("切换 webview 失败")
 
     @classmethod