我想使用google-chrome在EC2示例中运行一个简单的python代码,google-chrome在我的本地系统中运行良好虽然我已经安装了所有必需的软件包,但我无法运行脚本Google Chrome 109. 0. 5414. 119 ChromeDriver 109. 0. 5414. 74 selenium 4. 8. 0
当运行下面的简单脚本时
#######################
from selenium import webdriver
service = webdriver.chrome.service.Service('/usr/bin/chromedriver')
service.start()
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options = options.to_capabilities()
driver = webdriver.Remote(service.service_url, options)
driver.get("https://www.google.com")
###############################
我收到以下错误
######################### raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Stacktrace: \#0 0x55cd3bfbd303 \<unknown\> \#1 0x55cd3bd91d37 \<unknown\> \#2 0x55cd3bdba157 \<unknown\> \#3 0x55cd3bdb6330 \<unknown\> \#4 0x55cd3bdf74a6 \<unknown\> \#5 0x55cd3bdee753 \<unknown\> \#6 0x55cd3bdc1a14 \<unknown\> \#7 0x55cd3bdc2b7e \<unknown\> \#8 0x55cd3c00c32e \<unknown\> \#9 0x55cd3c00fc0e \<unknown\> \#10 0x55cd3bff2610 \<unknown\> \#11 0x55cd3c010c23 \<unknown\> \#12 0x55cd3bfe4545 \<unknown\> \#13 0x55cd3c0316a8 \<unknown\> \#14 0x55cd3c031836 \<unknown\> \#15 0x55cd3c04cd13 \<unknown\> \#16 0x7f0f6b23e44b start_thread
1条答案
按热度按时间wmtdaxz31#
我假设你正在运行一个Linux EC2示例,下面是在Ubuntu Linux EC2上运行代码的说明,其他操作系统会略有不同。
连接到EC2示例并运行:
或者将这些命令添加到EC2用户数据中:
然后将脚本更新为:
然后使用python3运行脚本,例如,如果文件名为
test.py
,则运行python3 test.py
。它将打印所请求网页的源代码,即
https://www.google.com