提问人:Tommaso Ascani 提问时间:10/21/2022 最后编辑:Tommaso Ascani 更新时间:10/21/2022 访问量:473
Docker 安装旧的 chromium 版本
Docker install old chromium version
问:
我正在创建一个安装 chromium 和 chromium-driver 的 Docker 映像,但每次运行 python 脚本时,它都会因渲染问题而崩溃。 错误返回以下内容:会话信息:无头 chrome=89.0.4389.114 所以我尝试直接在树莓上而不是在容器中安装所有这些包,并且该脚本在 chromium 和 chromium 驱动程序版本下运行良好:106.0.5249.119
为什么要安装docker文件旧版本?
Docker文件:
FROM python:3.9.2
RUN apt-get update
# install chromium
RUN apt-get install -y chromium
# install chromium-driver
RUN apt-get install chromium-driver
RUN /usr/local/bin/python -m pip install --upgrade pip
COPY . /data
WORKDIR /data
RUN pip install --no-cache-dir -r requirements.txt
# set display port to avoid crash
ENV DISPLAY=:0
# custom env vars
ENV DOCKER_IMAGE=true
错误:
Exception in thread Thread-5:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/data/****.py", line 799, in main_function
browser = browserSetup(True, PC_USER_AGENT)
File "/data/****.py", line 42, in browserSetup
chrome_browser_obj = webdriver.Chrome(options=options)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in __init__
super().__init__(
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 272, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 364, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from timeout: Timed out receiving message from renderer: 600.000
(Session info: headless chrome=89.0.4389.114)
浏览器创建python脚本:
from selenium.webdriver.chrome.options import Options
options = Options()
prGreen("[DOCKER] Setting flags for Docker")
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("user-agent=" + user_agent)
options.add_argument('lang=' + LANG.split("-")[0])
if headless_mode :
options.add_argument("--headless")
options.add_argument('log-level=3')
chrome_browser_obj = webdriver.Chrome(options=options)
return chrome_browser_obj
答: 暂无答案
评论