Skip to content

Commit

Permalink
refactor Dockerfile and update example
Browse files Browse the repository at this point in the history
  • Loading branch information
dimmg committed Nov 29, 2021
1 parent c364783 commit 9490eed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 && \
Expand All @@ -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
Expand Down
21 changes: 12 additions & 9 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver import firefox

logging.getLogger().setLevel(logging.INFO)

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -77,8 +82,6 @@ def phantomjs_example():
display.stop()




if __name__ == '__main__':
chrome_example()
firefox_example()
Expand Down

0 comments on commit 9490eed

Please sign in to comment.