我正在尝试在我的python脚本中使用Selenium库。
我正在使用Windows 10,并且已经下载了硒所需的最新chrome驱动程序。
虽然我已经在系统的 PATH 环境变量中添加了直到 chromedriver .exe 文件的路径,但我收到以下错误-
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error:
Chrome failed to start: was killed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location E:/pg/chromedriver.exe is no
longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.41.578737
(49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134
x86_64)
我在网络中搜索了此错误,并添加了如下所示的chrome选项参数-
if __name__ == "__main__":
options = wd.ChromeOptions()
options.accept_untrusted_certs = True
options.assume_untrusted_cert_issuer = True
options.add_argument("--no-sandbox")
options.add_argument("--disable-impl-side-painting")
options.add_argument("--disable-setuid-sandbox")
options.add_argument("--disable-seccomp-filter-sandbox")
options.add_argument("--disable-breakpad")
options.add_argument("--disable-client-side-phishing-detection")
options.add_argument("--disable-cast")
options.add_argument("--disable-cast-streaming-hw-encoding")
options.add_argument("--disable-cloud-import")
options.add_argument("--disable-popup-blocking")
options.add_argument("--ignore-certificate-errors")
options.add_argument("--disable-session-crashed-bubble")
options.add_argument("--disable-ipv6")
options.add_argument("--allow-http-screen-capture")
options.add_argument("--start-maximized")
options.binary_location = chrome_binary # chrome.exe
driver_binary = r"E:/pg/chromedriver.exe"
driver = wd.Chrome(driver_binary, chrome_options=options)
try:
login(driver)
followers = scrape_followers(driver, account)
print(followers)
following = scrape_following(driver, account)
print(following)
finally:
driver.quit()
但它并没有解决错误。
有没有人遇到过同样的问题?请帮我解决这个问题。
我能够解决我的问题。 我从chrome驱动程序路径中删除了"r"以及所有.add_argument((,现在它工作正常。 因此,与其使用driver_binary = r'E:pgchromedriver.exe'
我正在使用driver_binary = 'E:pgchromedriver.exe'