Seleniumbase in Docker #2642
AlejandroMova
started this conversation in
General
Replies: 1 comment 4 replies
-
Most of the args you set with
If you need to maximize the window, call |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I have been trying to dockerize my seleniumbase code, which works well outside of docker. The issue is, when in docker, I get a NoSuchElementException. What settings should my driver have or what should else should I change?
Thanks!
Python driver initialization:
sb = Driver(uc=True, browser='chrome', headless2=True, chromium_arg='--headless,start-maximized,disable-infobars,--disable-extensions,--disable-gpu,--disable-dev-shm-usage,--no-sandbox')
Dockerfile (similar to the provided on this github):
FROM ubuntu:18.04
#=======================================
Install Python and Basic Python Tools
#=======================================
RUN apt-get -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false update
RUN apt-get install -y python3 python3-pip python3-setuptools python3-dev python-distribute
RUN alias python=python3
RUN echo "alias python=python3" >> ~/.bashrc
#=================================
Install Bash Command Line Tools
#=================================
RUN apt-get -qy --no-install-recommends install
sudo
unzip
wget
curl
libxi6
libgconf-2-4
vim
xvfb
&& rm -rf /var/lib/apt/lists/*
#================
Install Chrome
#================
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - &&
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list &&
apt-get -yqq update &&
apt-get -yqq install google-chrome-stable &&
rm -rf /var/lib/apt/lists/*
#===========================
Configure Virtual Display
#===========================
RUN set -e
RUN echo "Starting X virtual framebuffer (Xvfb) in background..."
RUN Xvfb -ac :99 -screen 0 1280x1024x16 > /dev/null 2>&1 &
RUN export DISPLAY=:99
RUN exec "$@"
#=======================
Update Python Version
#=======================
RUN apt-get update -y
RUN apt-get -qy --no-install-recommends install python3.8
RUN rm /usr/bin/python3
RUN ln -s python3.8 /usr/bin/python3
#=============================================
Allow Special Characters in Python Programs
#=============================================
RUN export PYTHONIOENCODING=utf8
RUN echo "export PYTHONIOENCODING=utf8" >> ~/.bashrc
#=====================
Download WebDrivers
#=====================
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz
RUN tar -xvzf geckodriver-v0.34.0-linux64.tar.gz
RUN chmod +x geckodriver
RUN mv geckodriver /usr/local/bin/
RUN wget https://chromedriver.storage.googleapis.com/72.0.3626.69/chromedriver_linux64.zip
RUN unzip chromedriver_linux64.zip
RUN chmod +x chromedriver
RUN mv chromedriver /usr/local/bin/
#=======================
Create Virtual Environment
#=======================
RUN python3 -m pip install virtualenv &&
python3 -m virtualenv /venv
#============================
Set Working Directory
#============================
WORKDIR /linkedin_scraper
#=====================
Copy Source Code
#=====================
COPY ./src ./src
COPY requirements.txt .
#============================
Install Dependencies
#============================
RUN /venv/bin/python -m pip install --no-cache-dir -r requirements.txt
#========================
Default Command to Run
#========================
#CMD ["/venv/bin/python", "./src/main.py"]
Beta Was this translation helpful? Give feedback.
All reactions