From 66e1aca3f237fe09eea95d8924f0628b1f4b4429 Mon Sep 17 00:00:00 2001 From: dimmg Date: Tue, 7 Nov 2017 22:09:25 +0200 Subject: [PATCH] feat(core): add support for phantomjs webkit --- Dockerfile | 8 +++++++- README.md | 6 +++--- example.py | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8c1160e..3e4c098 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,6 +37,12 @@ RUN dpkg -i google-chrome*.deb RUN apt-get install -y -f +# install phantomjs + +RUN wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 && \ + tar -jxf phantomjs-2.1.1-linux-x86_64.tar.bz2 && cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs + + RUN pip3 install selenium RUN pip3 install pyvirtualdisplay @@ -47,4 +53,4 @@ WORKDIR /$APP_HOME COPY . $APP_HOME/ CMD tail -f /dev/null -# CMD python3 example.py \ No newline at end of file +# CMD python3 example.py diff --git a/README.md b/README.md index cdfca67..05f7b95 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## dockselpy -Dockerfile example on how to *"assemble"* together Selenium (with support for both Chrome and Firefox), Python and Xfvb. +Dockerfile example on how to *"assemble"* together Selenium (with support for Chrome, Firefox and PhantomJS), Python and Xfvb. ### Information @@ -10,6 +10,7 @@ led to the process of building my own version. The image is build with the following dependencies: - latest Chrome and chromedriver - latest Firefox and geckodriver +- latest stable PhantomJS webkit (v2.1.1) - Selenium - Python 3 - Xvfb and the python wrapper - pyvirtualdisplay @@ -48,5 +49,4 @@ display.stop() ``` -Detailed examples on how to use Firefox with custom profile and Google Chrome with desired options can be found in the -source. +Detailed examples on how to use Firefox with custom profile, Google Chrome with desired options or PhantomJS can be found in the source. diff --git a/example.py b/example.py index f168770..a485cf6 100644 --- a/example.py +++ b/example.py @@ -60,6 +60,26 @@ def firefox_example(): display.stop() +def phantomjs_example(): + display = Display(visible=0, size=(800, 600)) + display.start() + logging.info('Initialized virtual display..') + + browser = webdriver.PhantomJS() + logging.info('Initialized phantomjs browser..') + + browser.get(BASE_URL) + logging.info('Accessed %s ..', BASE_URL) + + logging.info('Page title: %s', browser.title) + + browser.quit() + display.stop() + + + + if __name__ == '__main__': chrome_example() firefox_example() + phantomjs_example()