From 9490eed0d0000d714ae3d79d6ffa91e749200163 Mon Sep 17 00:00:00 2001 From: dimmg Date: Mon, 29 Nov 2021 12:23:47 +0200 Subject: [PATCH] refactor Dockerfile and update example --- Dockerfile | 12 ++++++------ example.py | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1a9934f..b39ed0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ FROM ubuntu:focal -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install --no-install-recommends -y \ python3 python3-pip \ fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \ - libnspr4 libnss3 lsb-release xdg-utils libxss1 libdbus-glib-1-2 \ + libnspr4 libnss3 lsb-release xdg-utils libxss1 libdbus-glib-1-2 libgbm1 \ curl unzip wget \ - xvfb libgbm1 + xvfb # install geckodriver and firefox @@ -25,7 +26,7 @@ RUN FIREFOX_SETUP=firefox-setup.tar.bz2 && \ # install chromedriver and google-chrome -RUN apt install libgbm1 -y + RUN CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \ wget https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \ unzip chromedriver_linux64.zip -d /usr/bin && \ @@ -47,8 +48,7 @@ RUN wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x rm phantomjs-2.1.1-linux-x86_64.tar.bz2 -RUN pip3 install selenium -RUN pip3 install pyvirtualdisplay +RUN pip3 install selenium==3.141.0 pyvirtualdisplay==2.2 ENV LANG C.UTF-8 ENV LC_ALL C.UTF-8 diff --git a/example.py b/example.py index a485cf6..2801651 100644 --- a/example.py +++ b/example.py @@ -3,6 +3,7 @@ from pyvirtualdisplay import Display from selenium import webdriver +from selenium.webdriver import firefox logging.getLogger().setLevel(logging.INFO) @@ -23,7 +24,7 @@ def chrome_example(): }) logging.info('Prepared chrome options..') - browser = webdriver.Chrome(chrome_options=chrome_options) + browser = webdriver.Chrome(options=chrome_options) logging.info('Initialized chrome browser..') browser.get(BASE_URL) @@ -40,15 +41,19 @@ def firefox_example(): display.start() logging.info('Initialized virtual display..') - firefox_profile = webdriver.FirefoxProfile() - firefox_profile.set_preference('browser.download.folderList', 2) - firefox_profile.set_preference('browser.download.manager.showWhenStarting', False) - firefox_profile.set_preference('browser.download.dir', os.getcwd()) - firefox_profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv') + firefox_options = firefox.options.Options() + firefox_options.set_preference('browser.download.folderList', 2) + firefox_options.set_preference( + 'browser.download.manager.showWhenStarting', False + ) + firefox_options.set_preference('browser.download.dir', os.getcwd()) + firefox_options.set_preference( + 'browser.helperApps.neverAsk.saveToDisk', 'text/csv' + ) logging.info('Prepared firefox profile..') - browser = webdriver.Firefox(firefox_profile=firefox_profile) + browser = webdriver.Firefox(options=firefox_options) logging.info('Initialized firefox browser..') browser.get(BASE_URL) @@ -77,8 +82,6 @@ def phantomjs_example(): display.stop() - - if __name__ == '__main__': chrome_example() firefox_example()