问题描述
我正在尝试在 alpine 3.6
容器 (FROM alpine:3.6)
上运行 Selenium
.
I'm trying to run Selenium
on alpine 3.6
container (FROM alpine:3.6)
.
我在容器外壳中尝试的内容:
What I'm trying in container shell:
apk update
apk add python3
pip3 install -U selenium
apk add chromium
apk add chromium-driver
并运行以下python(使用python3):
And running the following python (using python3):
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'usr/bin/chromedriver') # Thrown an exception
并得到以下异常:
selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:崩溃(驱动程序信息:chromedriver=2.27 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 5.0.0-23-generic x86_64)
selenium=3.141.0
chromium=57.0.2987.133
chromeDriver=2.27
我该如何解决?
推荐答案
通过以下步骤解决(Work with alpine3.6):
Solved by the followings steps (Work with alpine3.6):
更新存储库:
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" > /etc/apk/repositories
echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories
Apk 更新:
apk update
安装 Chromium &铬驱动程序:
Install chromium & chromedriver:
apk add chromium
apk add chromium-chromedriver
安装python3、selenium:
Install python3, selenium:
apk add python3
pip3 install -U selenium
以下 python
代码适用于我:
And the following python
code works for me:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver.get('http://example.com')
这篇关于Selenium 在 alpine 3.6 容器上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!