GithubHelp home page GithubHelp logo

kevinhowbrook / selenium-python-docker-scraper Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 4.0 366 KB

A docker image for writing selenium stuffs

License: GNU General Public License v2.0

Python 72.50% Shell 3.72% Dockerfile 23.79%

selenium-python-docker-scraper's Introduction

Useful Docker Selenium container image for automation

Forked from: dimmg/dockselpy

BUILD IMAGE:

docker build -t selenium . (in the same path as the Dockerfile)

Running with fabric

Run fab help for tasks

  • fab run
    • Runs a container, mounting ./code and local /etc/hosts, runs ./code/main.py and removes the container when done
  • fab test
    • Runs a container, mounting ./code and local /etc/hosts, runs ./code/test.py and removes the container when done

RUN CONTAINER:

// run container, mount the python code, mount our local etc/hosts file, image to run (selenium) execute python
docker run --rm -v $(pwd)/code:/code -v /etc/hosts:/etc/hosts -it selenium python /code/main.py

ChromeDriverManager

This uses Webdriver Manager for Python to simplify management of binary drivers for different browsers. It's a massive headache keeping on top of these bianaries, ChromeDriverManager will install the needed bianary when it's defined, a la:

browser = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options)

EXAMPLE OF CODE WITH GOOGLE HEADLESS

from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

display = Display(visible=0, size=(1200, 800))
display.start()
# start Chrome
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--window-size=1200x800")
browser = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options)
browser.get('http://google.com/')
print(browser.title)
browser.quit()
display.stop()

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.