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