Giter Club home page Giter Club logo

dockselpy's Introduction

dockselpy

Dockerfile example on how to "assemble" together Selenium (with support for Chrome, Firefox and PhantomJS), Python and Xfvb.

Information

Recent struggle with finding a docker image for Selenium that supports headless versions for both Firefox and Chrome, 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

Running:

  • docker

    docker build -t selenium_docker .
    docker run --privileged -p 4000:4000 -d -it selenium_docker 
    
  • docker-compose

    docker-compose stop && docker-compose build && docker-compose up -d
    

Example

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()

browser = webdriver.Firefox()
browser.get('https://www.google.com/')
print(browser.title)

browser.quit()
display.stop()

Detailed examples on how to use Firefox with custom profile, Google Chrome with desired options or PhantomJS can be found in the source.

dockselpy's People

Contributors

dimmg avatar maxsor avatar nikolas-pvs avatar steve-tech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dockselpy's Issues

Got issue when building new image from Dockerfile

Hi there,

When I run the command:
docker build -t selenium_docker .
In the phase of installing google-chrome-stable, I got the following issue:

Unpacking google-chrome-stable (89.0.4389.82-1) ...
dpkg: dependency problems prevent configuration of google-chrome-stable:
 google-chrome-stable depends on libgbm1 (>= 8.1~0); however:
  Package libgbm1 is not installed.

dpkg: error processing package google-chrome-stable (--install):
 dependency problems - leaving unconfigured

I guess that the base environment is missing libgbm1 library then I updated the Dockerfile to prior of google-chrome-stable step:
RUN apt-get update & apt-get install -y libgbm1
Then try again and I am able to build the new image as expected.

Environment: MacOS

Please contact me if you have any questions!

Using Proxies on Chromedriver

Hi Dim! Why do you think I can't connect using proxies?

def selenium_connect():
        PROXY = "66.97.38.58:80"
        url = "http://whatsmyip.org"
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-dev-shm-usage')
        chrome_options.add_argument('--proxy-server=%s' % PROXY)
        driver = webdriver.Chrome(chrome_options=chrome_options)
        driver.get(url)

Been struggling with these and can't seem to find a way.

[BUG] Error when trying to fetch the GECKODRIVER_VERSION

There is an issue when trying to fetch the GECKODRIVER_VERSION, the command returns a non-zero code (1).

I found a simple fix if you're having this issue, you just have to edit the command into this: curl -i https://github.com/mozilla/geckodriver/releases/latest | grep -Po 'v[0-9]+.[0-9]+.[0-9]+' and it works perfectly.

I'll create a P/R that includes this fix.

Add Every Possible Type of Browser

I think we should add more type of browser like Edge and Safari. I realize there will be a drawback in the size of the image. But it can be solved by telling the developer to comment unused browser in Dockerfile.

Publish to dockselpy to DockerHub

Several people have published this container to DockerHub but those forks have since diverged from this project and it would be really helpful to always have the canonical version of this project available on DockerHub instead.

No matching distribution found for libu2f-udev

Hello, I am getting the build error No matching distribution found for libu2f-udev
How would I add libu2f-udev?
I have left comments with what I tried below.

FROM ubuntu.jammy:latest
## note tried focal as well... didn't work
ARG DEBIAN_FRONTEND=noninteractive
RUN echo "===> Installing system dependencies..." && \
    BUILD_DEPS="curl unzip" && \
    apt-get update && apt-get install --no-install-recommends -y \
    python3 python3-pip wget \
    fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \
    ## adding libu2f-udev after libvulkan1 did not work...
    libnspr4 libnss3 lsb-release xdg-utils libxss1 libdbus-glib-1-2 libgbm1 libvulkan1 \
    $BUILD_DEPS \
    xvfb

## does not work..
RUN wget http://archive.ubuntu.com/ubuntu/pool/main/libu/libu2f-host/libu2f-udev_1.1.4-1_all.deb && \
    dpkg -i libu2f-udev_1.1.4-1_all.deb

## also does not work 
# RUN apt-get install equivs -y && \
#     equivs-control libu2f-udev && \
#     equivs-build libu2f-udev && \
#     dpkg -i libu2f-udev_1.0_all.deb


RUN echo "===> Installing chromedriver and google-chrome..." && \
    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 && \
    chmod +x /usr/bin/chromedriver && \
    rm chromedriver_linux64.zip && \
    \
    CHROME_SETUP=google-chrome.deb && \
    wget -O $CHROME_SETUP "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" && \
    dpkg -i $CHROME_SETUP && \
    apt-get install -y -f && \
    rm $CHROME_SETUP

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PCD_FILE pcd_file
ENV PYTHONUNBUFFERED=1

ENV APP_HOME /usr/src/app
WORKDIR /$APP_HOME


COPY . $APP_HOME/
RUN pip3 install --trusted-host pypi.python.org -r $APP_HOME/requirements.txt


CMD tail -f /dev/null

CMD python3 mscript.py

Outdated Version of `urllib3`

Nice dockerfile, thanks! For anyone else, I got the following error after running the dockerfile and then executing docker exec <hash> python3 example.py.

INFO:root:Initialized virtual display..
INFO:root:Prepared chrome options..
Traceback (most recent call last):
  File "example.py", line 83, in <module>
    chrome_example()
  File "example.py", line 26, in chrome_example
    browser = webdriver.Chrome()#chrome_options=chrome_options)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 251, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 318, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/remote_connection.py", line 375, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/remote_connection.py", line 397, in _request
    resp = self._conn.request(method, url, body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 79, in request
    **urlopen_kw)
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 142, in request_encode_body
    **urlopen_kw)
TypeError: urlopen() got multiple values for keyword argument 'body'

This is because I had version 1.7.1 of urllib3 installed in the image (I'm guessing this is the latest one in the repository. See this stackoverflow link

I fixed this issue by adding the following line RUN pip3 install urllib3 --upgrade to line 48 of the dockerfile. Pip complains about system packages but does install the correct one (you can check by adding RUN python3 -c "import urllib3; print(urllib3.__version__)" to the last line of the docker file)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.