|
@@ -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)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
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
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -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("--incognito")
|
|
|
+
|
|
|
driver = webdriver.Remote(
|
|
|
command_executor='http://127.0.0.1:4444/wd/hub',
|
|
|
options=options
|