当我同时使用两个参数--headless
和user-data-dir
时。硒引发selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
异常。如果仅使用其中的1个,那么一切都会按需工作。
我试图交换参数并删除其中的一些参数。 指定chromedriver.exe的完整路径。 这些都没有帮助。
chromeOptions.add_argument(“-disable-dev-shm-using”)不帮助我。
login = "test"
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
chromeOptions.add_argument("--no-sandbox")
chromeOptions.add_argument("--disable-setuid-sandbox")
chromeOptions.add_argument("--disable-dev-shm-using")
chromeOptions.add_argument("--disable-extensions")
chromeOptions.add_argument("--disable-gpu")
chromeOptions.add_argument("start-maximized")
chromeOptions.add_argument("disable-infobars")
chromeOptions.add_argument("--headless")
chromeOptions.add_argument(r"user-data-dir=.\cookies\\" + login)
b = webdriver.Chrome(chrome_options=chromeOptions)
b.get("https://google.com/")
b.quit()
答案 0 :(得分:0)
我通过添加参数login = "test"
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
chromeOptions.add_argument("--no-sandbox")
chromeOptions.add_argument("--disable-setuid-sandbox")
chromeOptions.add_argument("--remote-debugging-port=9222") # this
chromeOptions.add_argument("--disable-dev-shm-using")
chromeOptions.add_argument("--disable-extensions")
chromeOptions.add_argument("--disable-gpu")
chromeOptions.add_argument("start-maximized")
chromeOptions.add_argument("disable-infobars")
chromeOptions.add_argument("--headless")
chromeOptions.add_argument(r"user-data-dir=.\cookies\\" + login)
b = webdriver.Chrome(chrome_options=chromeOptions)
b.get("https://google.com/")
b.quit()
\r