-1

When I try to run docker container I get the following error. When I checked the link in the error it says it's due to the python file being unable to find the webdriver file however I copied the webdriver file into the working directory of the docker container with the COPY command while writing the docker file:

Traceback (most recent call last):
  File "/app/scraper_exe.py", line 3, in <module>
    bot = Scraper()
          ^^^^^^^^^
  File "/app/scraper.py", line 25, in __init__
    self.driver = webdriver.Chrome(service=service, options=options)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 51, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py", line 44, in get_path
    raise NoSuchDriverException(f"Unable to locate or obtain driver for {options.capabilities['browserName']}")
selenium.common.exceptions.NoSuchDriverException: Message: Unable to locate or obtain driver for chrome; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

This is what my dockerfile looks like:

FROM python:3.11.4-bookworm

WORKDIR /app

COPY . /app/

RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -

RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'

RUN apt-get -y update

RUN apt-get install -y google-chrome-stable

RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip

RUN apt-get install -yqq unzip

RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/

RUN pip3 install -r requirements.txt

CMD ["python", "scraper_exe.py"] 

This is what's in my requirements file:

selenium
pandas
urllib3
boto3
click

This is what's in the folder containing the dockerfile:

$ ls
__pycache__/  chromedriver.exe*  data_pipeline_scraper.ipynb  Dockerfile  requirements.txt  scraper.py  scraper_exe.py  
DaveL17
  • 1,673
  • 7
  • 24
  • 38
Corbie
  • 1
  • 2

1 Answers1

-1

You seem to be on a based docker and instead of the zip file you need to get the tar/tar.gz files.

So instead of:

RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip

you need:

RUN wget -O /tmp/chromedriver.tar.gz http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.tar.gz

Likewise, instead of:

RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/

you need:

RUN untar /tmp/chromedriver.tar chromedriver -d /usr/local/bin/
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • The chromedriver file that is being retrieved is a zip file and not a tar file so the request cannot be fulfilled. This is illustrated by the following error when I try to build the dockerfile: ERROR: failed to solve: process "/bin/sh -c wget -O /tmp/chromedriver.tar.gz http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.tar.gz" did not complete successfully: exit code: 8 – Corbie Aug 05 '23 at 10:00