我正在嘗試使用基本 python:3.7 映像運行 Selenium 腳本,但我有點不確定如何安裝所需的依賴項。我遇到了其他幾個關于使用不同影像(如 selenium/standalone-chrome)的問題,但是,我有幾個其他腳本不使用 Selenium 在這個容器上運行,所以我有點猶豫要不要改變它。
我可以在這個影像上運行 Selenium 嗎?或者,如果我將其更改為 selenium/standalone-chrome 會影響我應用程式的其余部分。我正在運行一個燒瓶 API。
這是我現在面臨的錯誤,
selenium.common.exceptions.WebDriverException: Message: Service <path> unexpectedly exited. Status code was: 127
請注意,我只安裝了 pip 硒,沒有安裝其他依賴項,如 chrome。
uj5u.com熱心網友回復:
正確的用例是讓selenium/standalone-chrome容器運行并單獨擁有一個運行測驗代碼的容器。
在docker-compose'RemoteWebDriver'的幫助下,你運行你的“集群”并且你的測驗參考遠程selenium容器。
uj5u.com熱心網友回復:
我能夠在這里找到我需要的東西, https://dev.to/nazliander/using-selenium-within-a-docker-container-ghp
可以將以下命令添加到您的 Dockerfile 以安裝 Chrome 驅動程式以運行 Selenium,
# Adding trusting keys to apt for repositories
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
# Adding Google Chrome to the repositories
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
# Updating apt to see and install Google Chrome
RUN apt-get -y update
# Install Google Chrome
RUN apt-get install -y google-chrome-stable
# Installing Unzip
RUN apt-get install -yqq unzip
# Download the Chrome Driver
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
# Unzip the Chrome Driver into /usr/local/bin directory
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
# Set display port as an environment variable
ENV DISPLAY=:99
請注意,這適用于我一直在使用的 python:3.7 基礎映像。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/334706.html
