Evy*_*tar 3 python selenium selenium-chromedriver alpine-linux
我正在尝试在容器Selenium上运行。alpine 3.6(FROM alpine:3.6)
我在容器外壳中尝试的内容:
apk update
apk add python3
pip3 install -U selenium
apk add chromium
apk add chromium-driver
Run Code Online (Sandbox Code Playgroud)
并运行以下 python(使用 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
Run Code Online (Sandbox Code Playgroud)
并得到以下异常:
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
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
通过以下步骤解决(使用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
Run Code Online (Sandbox Code Playgroud)
应用程序更新:
apk update
Run Code Online (Sandbox Code Playgroud)
安装 chrome 和 chromedriver:
apk add chromium
apk add chromium-chromedriver
Run Code Online (Sandbox Code Playgroud)
安装python3、selenium:
apk add python3
pip3 install -U selenium
Run Code Online (Sandbox Code Playgroud)
以下python代码对我有用:
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')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10750 次 |
| 最近记录: |