Jared %!s(int64=2) %!d(string=hai) anos
pai
achega
36d111277b
Modificáronse 1 ficheiros con 21 adicións e 2 borrados
  1. 21 2
      monitor/test_wd.py

+ 21 - 2
monitor/test_wd.py

@@ -10,6 +10,7 @@ from selenium.webdriver.common.by import By
 from selenium.webdriver.chrome.service import Service
 from selenium.webdriver.support import expected_conditions as EC
 import codecs
+from selenium_stealth import stealth
 import random
 import requests
 import datetime
@@ -59,6 +60,16 @@ def process_query(qs):
     global driver
     googleurl = 'https://www.google.com/search?q={}&num={}&hl={}'.format(urllib.parse.quote(q), 100,'zh-TW')
     print(googleurl)
+
+#    stealth(driver,
+#        languages=["en-US", "en"],
+#        vendor="Google Inc.",
+#        platform="Win32",
+#        webgl_vendor="Intel Inc.",
+#        renderer="Intel Iris OpenGL Engine",
+#        fix_hairline=True,
+#        )
+
     driver.get(googleurl)
     time.sleep(6)
 
@@ -72,7 +83,13 @@ def process_query(qs):
 
     idx=1
     ranking=-1
-    print('搜尋結果數量',len(elmts))
+    lenelmts=len(elmts)
+    print('搜尋結果數量',lenelmts)
+    if lenelmts <=0:
+        os.system('docker container restart p4444')
+        return
+
+
     # if len(elmts) <=0:
     #     send_msg('network failed...')
 #    driver.save_screenshot('c:/tmp/test.png')
@@ -103,8 +120,10 @@ def run_once(q):
     options.add_argument('--headless')
     options.add_argument("--no-sandbox")
     options.add_argument("--disable-dev-shm-usage")
+    options.add_argument('--disable-blink-features=AutomationControlled') 
+
 #    options.add_argument("--user-agent=" +user_agent)
-    options.add_argument("--incognito")
+#    options.add_argument("--incognito")
     driver = webdriver.Remote(
             command_executor='http://127.0.0.1:4444/wd/hub',
             options=options