Trouble with Web Scraping in Docker Using Selenium

0
6
Asked By CleverCactus99 On

I'm trying to set up web scraping using Selenium in a Docker container, and I've crafted this Dockerfile,but I'm hitting a roadblock because it doesn't seem to work as expected. Here's my Dockerfile for reference:

```
FROM python:3.11-slim

# Installing the necessary dependencies
RUN apt-get update && apt-get install -y --no-install-recommends
vim
chromium
chromium-driver
&& rm -rf /var/lib/apt/lists/*

# Set environment variables
ENV CHROME_BIN=/usr/bin/chromium
ENV CHROME_DRIVER=/usr/bin/chromedriver

# Set working directory
WORKDIR /app

# Copy files
COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

# Expose port 8000 for Django
EXPOSE 8000

# Start the Django server
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
```

When I build the image, I get errors. Can someone help diagnose what might be going wrong?

2 Answers

Answered By DockerDev123 On

You might want to try using one of the official Selenium base images instead of starting from the basic Python slim image. These images are pre-configured with everything needed for Selenium to work properly. Check out the [Selenium Docker repository](https://github.com/SeleniumHQ/docker-selenium) for some good starting points.

Answered By DebuggingDiva On

It looks like you're encountering a `SessionNotCreatedException`. This error generally means that your ChromeDriver version doesn't match the version of Chrome you're trying to use. According to the error message, your ChromeDriver only supports Chrome version 114, but the version you're running is 136.0.7103.59. Make sure you update your ChromeDriver to a compatible version!

SeleniumSleuth -

Exactly! It’s right there in the stacktrace. Just a quick update to ChromeDriver should fix the problem.

BrowserBuddy -

Yeah, the error message clearly states the version mismatch! Just update ChromeDriver and it should work.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.