zooeytsai 2 years ago
parent
commit
b3cd4ad0a2
1 changed files with 5 additions and 13 deletions
  1. 5 13
      web/main.py

+ 5 - 13
web/main.py

@@ -131,27 +131,19 @@ async def func_expand(kw: str = Form(...),kw2:Optional[str] = Form(None),kw3:Opt
 
 def restart_browser():
     global driver
-    while True:
-        try:
-            os.system('docker container restart tiny1')
-            time.sleep(1)
-            break
-        except:
-            os.system('docker container restart tiny1')
-            time.sleep(10)
     if driver is not None:
         print('closing')
         driver.quit()
-        driver=None
+        driver = None
     try: 
         options = webdriver.ChromeOptions()
         options.add_argument("--no-sandbox")
-        #options.add_argument("--disable-dev-shm-usage")
+        options.add_argument("--disable-dev-shm-usage")
         options.add_argument('--headless')
-        options.add_experimental_option("debuggerAddress", "127.0.0.1:9923")
+        # options.add_experimental_option("debuggerAddress", "127.0.0.1:9923")
         options.add_argument("--incognito")
         try:
-            driver = webdriver.Chrome(options=options,executable_path='/root/driver/chromedriver')
+            driver = webdriver.Chrome(options=options,executable_path='/root/driver/chromedriver103')
             #driver = webdriver.Remote(command_executor='http://127.0.0.1:'+str(portnum)+'/wd/hub',options=options)
         except:
             return None
@@ -206,7 +198,7 @@ async def ranking(kw: str = Form(...), domain:str = Form(...),kw2:Optional[str]
         result.append(datadict)
         print(domain_name)
         print(datadict)
-        web_driver.quit()
+        driver.quit()
         print('數量',len(elmts))
         time.sleep(90)