diff --git a/Dockerfile b/Dockerfile index e1e4eee..21b5233 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,38 @@ FROM python:3.8-slim +# Installing google chrome +# Adding trusting keys to apt for repositories +RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - + +# Adding Google Chrome to the repositories +RUN sh -c 'echo "deb [arch=arm64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' + +# Updating apt to see and install Google Chrome +RUN apt-get -y update + +# Magic happens +RUN apt-get install -y google-chrome-stable + +# Installing chromium driver +# Installing Unzip +RUN apt-get install -yqq unzip + +# Download the Chrome Driver +RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/` \ +curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE \ +`/chromedriver_linux64.zip + +# Unzip the Chrome Driver into /usr/local/bin directory +RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ + +# Set display port as an environment variable +ENV DISPLAY=:99 + +# Pip stuff +RUN pip install --upgrade pip +RUN python3 -m venv /venv + +# Python packages # pip install fastapi[all] # pip install requests # pip install selenium @@ -11,9 +44,6 @@ FROM python:3.8-slim # pip install Pillow # pip install aiofiles - -RUN python3 -m venv /venv - RUN . /venv/bin/activate && pip install --no-cache-dir \ aiofiles==22.1.0 anyio==3.6.2 async-generator==1.10 attrs==22.2.0 beautifulsoup4==4.11.1 \ certifi==2022.12.7 charset-normalizer==3.0.1 click==8.1.3 dnspython==2.2.1 email-validator==1.3.0 \ diff --git a/examples/selenium.py b/examples/selenium.py new file mode 100644 index 0000000..21dade4 --- /dev/null +++ b/examples/selenium.py @@ -0,0 +1,21 @@ +from selenium.webdriver.chrome.options import Options +from selenium import webdriver + +def set_chrome_options() -> None: + """Sets chrome options for Selenium. + Chrome options for headless browser is enabled. + """ + chrome_options = Options() + chrome_options.add_argument("--headless") + chrome_options.add_argument("--no-sandbox") + chrome_options.add_argument("--disable-dev-shm-usage") + chrome_prefs = {} + chrome_options.experimental_options["prefs"] = chrome_prefs + chrome_prefs["profile.default_content_settings"] = {"images": 2} + return chrome_options + +if __name__ == "__main__": + chrome_options = set_chrome_options() + driver = webdriver.Chrome(options=chrome_options) + # Do stuff with your driver + driver.close() \ No newline at end of file