这不是其他问题的重复,我也尝试了现有的答案。在AWS ec2上,我创建了一个docker容器,试图在其中打开无头的chrome。码头工人文件是
FROM python:3
# Install Chrome for Selenium
RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb
RUN dpkg -i /chrome.deb || apt-get install -yf
RUN rm /chrome.deb
RUN wget https://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip
RUN unzip chromedriver_linux64.zip -d chromedriver
RUN chmod +x /chromedriver/chromedriver
ENV PATH="/chromedriver:${PATH}"
RUN echo 'logging path'
RUN echo "${PATH}"
我用来打开浏览器的代码是:
options = Options()
options.add_argument("--window-size=1920,1080")
options.add_argument("--disable-gpu")
options.add_argument("--disable-extensions")
options.add_argument("--proxy-server='direct://'")
options.add_argument("--proxy-bypass-list=*")
options.add_argument("--start-maximized")
options.add_argument("--headless")
options.add_argument('--no-sandbox')
options.headless = True
driver = webdriver.Chrome(options=options, executable_path='/chromedriver/chromedriver')
driver.get(url)
ec2上的错误是:
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /chromedriver/chromedriver unexpectedly exited. Status code was: 127
我也尝试过
Installing Chromium on Amazon Linux和其他stackoverflow答案,但无法解决。
Google-chrome版本-Google Chrome 75.0.3770.100
驱动程序版本-2.38
硒-3.141.0
AWS AMI的操作系统是Linux,而不是ubuntu。 grep没有帮助。即使我也解决了该问题,仍然出现错误。记录chromedriver的路径后,记录如下
/usr/local/lib/python3.7/site-packages/chromedriver_binary:/chromedriver:
答案 0 :(得分:0)
我有一个类似的错误,该错误是通过安装xvfb修复的,这是必需的,因为您正在运行chrome的无头会话。尝试做apt-get install xvfb