我想创建多线程程序来检查页面,但我无法一次启动多个浏览器。
import from selenium.webdriver.chrome.options import Options
import undetected_chromedriver
from threading import Thread
from time import sleep
import os
mainDir = os.path.abspath(os.curdir)
def CreateBrowser():
chrome_options = Options()
chrome_options.add_argument("--window-size=800,900")
chrome_options.add_argument('--profile-directory=' + str(int(time.time())))
driver = undetected_chromedriver.Chrome(driver_executable_path=mainDir + '\\chromedriver.exe', browser_executable_path=f'{mainDir}\\utils\chrome\GoogleChromePortable\GoogleChromePortable.exe',
options=chrome_options)
driver.get("https://google.com")
sleep(60)
driver.close()
driver.quit()
if __name__ == '__main__':
Thread(target=CreateBrowser).start()
Thread(target=CreateBrowser).start()
退货:
问题原来是我使用了Portable版本,可能是重新编译了,启动的是 chrome-portable.exe ,里面是一个文件夹 APP-bin-chrome.exe 。我更改了启动路径,一切开始完美运行
我面临着同样的问题,它一直告诉我正在使用 chromedriver
您是如何解决这个问题的?我想像你一样在多线程中使用 unDetected_chromedriver,你能解释一下吗?谢谢你