简体   繁体   English

Selenium with Python - Chromedriver 必须在 PATH 中

[英]Selenium with Python - Chromedriver have to be in PATH

Since more than 2 hours I'm trying to set Selenium in python with chrome on un container alpine.由于超过 2 个小时,我试图在 python 中设置 Selenium,在 un container alpine 上使用 chrome。 I don't know why I have this error message :我不知道为什么会出现此错误消息:

    browser = webdriver.Chrome()
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
    self.service.start()
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

I don't understand because the google driver is in path look:我不明白,因为谷歌驱动程序在路径中: 在此处输入图片说明

Someone can help me please ?有人可以帮我吗? Thank a lot非常感谢

PS : this is a part of my dockerfile PS:这是我的dockerfile的一部分

    RUN wget "https://chromedriver.storage.googleapis.com/2.36/chromedriver_linux64.zip" &&\
    busybox unzip chromedriver_linux64.zip &&\
    chmod a+x chromedriver &&\
    mv chromedriver /usr/bin/

this is my methode :这是我的方法:

    def __init__(self, url, parser = "lxml") :
       self.url = url
       self.parser = parser
       browser = webdriver.Chrome()
       browser.get(self.url)
       ...

ps : dockerfile : ps:dockerfile:

FROM alpine:3.7

RUN apk add --update bash &&\
    apk update &&\
    apk upgrade

RUN apk add --no-cache python-dev ;\
    apk add --no-cache python

#telecharge lib python scraper
RUN apk add --no-cache py-pip &&\
    apk add --no-cache linux-headers &&\
    apk add --no-cache texinfo &&\
    apk add --no-cache gcc &&\
    apk add --no-cache g++ &&\
    apk add --no-cache gfortran &&\
    apk add --no-cache libxml2-dev &&\
    apk add --no-cache xmlsec-dev &&\
    apk add --no-cache py-requests &&\
    apk add --no-cache chromium &&\
    apk add --no-cache chromium-chromedriver

#install lib python scraper
RUN pip install beautifulsoup4 &&\
    pip install requests &&\
    pip install lxml &&\
    pip install html5lib &&\
    pip install urllib3 &&\
    pip install -U selenium

#telecharge driver pour selenium
RUN wget "https://chromedriver.storage.googleapis.com/2.36/chromedriver_linux64.zip" &&\
    busybox unzip chromedriver_linux64.zip &&\
    chmod a+x chromedriver &&\
    mv chromedriver /usr/bin/

# prepare le shell
CMD ["bash"]
WORKDIR "/root"

I didn't use Chrome but firefox, This is all of my dockerfile.我用的不是 Chrome,而是 firefox,这是我所有的 dockerfile。 it's work for me.这对我有用。 I hope That will help you.我希望这会帮助你。 Have fun玩得开心

FROM alpine:3.7

RUN apk add --no-cache bash &&\
    apk update &&\
    apk upgrade

ENV PATH /usr/local/bin:$PATH

RUN apk add --no-cache make &&\
    apk add --no-cache python3-dev &&\
    apk add --no-cache python3 &&\
    apk add --no-cache firefox-esr &&\
    apk add --no-cache wget &&\
    apk add --no-cache git &&\
    apk add --no-cache icu-libs &&\
    apk add --no-cache xvfb &&\
    apk add --no-cache linux-headers &&\
    apk add --no-cache texinfo &&\
    apk add --no-cache gcc &&\
    apk add --no-cache g++ &&\
    apk add --no-cache gfortran &&\
    apk add --no-cache libxml2-dev &&\
    apk add --no-cache xmlsec-dev &&\
    apk add --no-cache py-requests &&\
    apk add --no-cache qt-dev &&\
    apk add --no-cache openjdk7-jre &&\
    apk add --no-cache dbus-x11 &&\
    apk add --no-cache ttf-freefont &&\
    rm -rf /var/cache/apk/*

#python
RUN python3 -m ensurepip &&\
    rm -r /usr/lib/python*/ensurepip &&\
    pip3 install --upgrade pip setuptools &&\
    if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi &&\
    if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi &&\
    rm -r /root/.cache

#firefox
RUN rm  -rf /tmp/* /var/cache/apk/* &&\
    wget "https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz" &&\
    tar -xvf geckodriver-v0.19.1-linux64.tar.gz &&\
    rm -rf geckodriver-v0.19.1-linux64.tar.gz &&\
    chmod a+x geckodriver &&\
    mv geckodriver /usr/local/bin/

#selenium
RUN pip install "selenium<3" &&\
    pip install virtualenv &&\
    pip install pyvirtualdisplay

#X server
RUN git clone "https://github.com/niklasb/webkit-server.git" &&\
    cd webkit-server &&\
    python setup.py install
ADD start_script.sh /tmp/start_script.sh
RUN chmod +x /tmp/start_script.sh

#mysql
RUN apk add --no-cache mariadb-dev
RUN pip install mysqlclient

# prepare le shell
RUN mkdir /var/shared
WORKDIR "/var/shared"
CMD ["/tmp/start_script.sh"]

And the start script:和启动脚本:

#!/bin/sh
Xvfb :00 &
export DISPLAY=:00
python3 scraper/main.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM