Skip to content

Instantly share code, notes, and snippets.

@hltbra
Last active April 2, 2018 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hltbra/3e9f02492389fdf9255f59dc9c24c485 to your computer and use it in GitHub Desktop.
Save hltbra/3e9f02492389fdf9255f59dc9c24c485 to your computer and use it in GitHub Desktop.
Docker + Selenium POC with headless Chrome
docker build -t poc-selenium:1 .
docker run --rm poc-selenium:1
from __future__ import print_function
from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = '/usr/bin/google-chrome-stable'
options.add_argument('headless')
options.add_argument('no-sandbox')
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://httpbin.org/ip")
print("IP: {}".format(driver.page_source))
driver.get("https://httpbin.org/headers")
print("Headers: {}".format(driver.page_source))
FROM python:2.7
RUN apt-get update && \
apt-get install -y locales-all apt-transport-https unzip && \
curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
apt-get update && \
apt-get install -y google-chrome-stable && \
wget https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip && \
unzip chromedriver_linux64.zip && \
mv chromedriver /usr/bin/
RUN pip install selenium
COPY app.py /app.py
CMD python /app.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment