问题描述
我在python项目中使用了硒的chromedriver.
I am using selenium's chromedriver in my python project.
我正在成功构建我的Dockerfile:
I am building successfully my Dockerfile:
FROM ubuntu:17.04
FROM selenium/standalone-chrome
FROM python:3.6
RUN apt update
RUN apt-get install -y libnss3 libgconf-2-4
ADD ./requirements.txt /tmp/requirements.txt
RUN python -m pip install -r /tmp/requirements.txt
ADD . /opt/example1/
# rights?
RUN chmod +x /opt/example1/assets/chromedriver
WORKDIR /opt/example1
CMD ["python","-u","program.py"]
但是当我运行docker容器时,出现以下错误:
But when I run my docker container I got following error:
任何人都知道我该怎么做才能防止此错误?是什么原因导致此崩溃?
Anyone got an idea what could I do to prevent this error?What is causing this crash?
这是我的发生错误的初始化代码:
Here is my initialization code where error occurs:
CHROME_DRIVER_PATH = os.path.abspath('assets/chromedriver')
class MdCrawler(Crawler):
def __init__(self, start_url, source):
super().__init__(start_url, source)
serialized_arr = self.read_data_from_json_file(JSON_FILE_PATH)
self.sent_ids = [] if serialized_arr is None else serialized_arr
>>> self.web_driver_chrome = webdriver.Chrome(executable_path=CHROME_DRIVER_PATH)
exit(1)
我已经编辑了Dockerfile(添加了ubuntu:17.04和aptget libnss3 libgconf-2-4).构建了我的docker镜像后,出现了另一个错误:
I have edited Dockerfile (added ubuntu:17.04 and aptget libnss3 libgconf-2-4). After building my docker image, I got different error:
我已添加
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update
RUN apt-get install -y google-chrome-stable
对于我的Dockerfile,但是新错误即将出现:
To my Dockerfile, but new error is coming:
推荐答案
我在Docker容器中的Selenium chromedriver最小测试脚本如下:
My minimal test script for Selenium chromedriver inside my Docker container looks like this:
import selenium.webdriver
options = selenium.webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = selenium.webdriver.Chrome(chrome_options=options)
driver.get('https://www.python.org/')
print(driver.title)
driver.close()
因此,您好像缺少了--headless
和--no-sandbox
自变量.
So it looks like you're missing --headless
and --no-sandbox
arguments.
这篇关于Docker Selenium:selenium.common.exceptions.WebDriverException:消息:服务chromedriver意外退出.状态码为:127的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!