Added selenium driver.
Some checks failed
Home Cluster Builds/Image-FastApi-Arm64/pipeline/head There was a failure building this commit

This commit is contained in:
2023-01-13 10:15:30 +02:00
parent c6b462bb7f
commit 2def52546b
2 changed files with 54 additions and 3 deletions

View File

@@ -1,5 +1,38 @@
FROM python:3.8-slim 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 fastapi[all]
# pip install requests # pip install requests
# pip install selenium # pip install selenium
@@ -11,9 +44,6 @@ FROM python:3.8-slim
# pip install Pillow # pip install Pillow
# pip install aiofiles # pip install aiofiles
RUN python3 -m venv /venv
RUN . /venv/bin/activate && pip install --no-cache-dir \ 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 \ 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 \ certifi==2022.12.7 charset-normalizer==3.0.1 click==8.1.3 dnspython==2.2.1 email-validator==1.3.0 \

21
examples/selenium.py Normal file
View File

@@ -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()