Sign inSign up

cheng3969/selenium

By cheng3969

•Updated over 2 years ago

Selenium & Chrome for web automation, with openpyxl, pyotp, and pyperclip modules pre-installed.

Image
0

98

cheng3969/selenium repository overview

Usage:

docker run [-d] [-it] [--rm] -v ${host_dir}:${container_dir} -w ${container_dir} cheng3969/selenium:${tagname} python3 [-u] ${app.py}

Docker Command Explanation:

  1. docker run: The base command for Docker, used to create and start a new container.
  2. -d or --detach: Run the container in detached mode, which means the container will run in the background and return the container ID. This option allows you to run the container without attaching to it interactively. If you choose to use this flag, the container will run in the background, and you can use docker logs to view the container's output or docker attach to connect to the container later.
  3. -it: This flag combines -i (interactive) and -t (allocate a pseudo-TTY), allowing you to interact with the container's process in the terminal.
  4. --rm: This flag tells Docker to automatically remove the container when it exits, which helps to keep your system clean of stopped containers.
  5. -v <host_dir:container_dir>: This flag mounts a directory from the host system to the container. Replace <host_dir> with the path to the directory on your host machine, and <container_dir> with the path to the directory inside the container where you want the host directory to be mounted.
  6. -w <container_dir>: This flag sets the working directory for the container to <container_dir>. Replace <container_dir> with the desired working directory inside the container.
  7. cheng3969/selenium:<tagname>: This is the name of the Docker image that you want to use for the container. Replace <tagname> with the specific tag of the cheng3969/selenium image you want to use.
  8. -u is a command-line flag for the Python interpreter that disables output buffering. When using the -u flag, the output from your Python script will be displayed in real-time, without being buffered in memory first.
  9. python3 <app.py>: This is the command that will be executed inside the container. In this case, it runs a Python 3 script. Replace <app.py> with the actual name of your Python script, headless mode, no sandbox, and disabling shared memory usage is required in your script.

Python code example:
app.py

# Import the required modules
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

# Create a Chrome options object to configure the browser
chrome_options = Options()

# Add arguments for headless mode, no sandbox, and disabling shared memory usage
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

# Set the path to the Chromedriver executable
chrome_driver_path = "/usr/lib/chromium-browser/chromedriver"

# Create a Service object using the Chromedriver path
service = Service(executable_path=chrome_driver_path)

# Initialize a Chrome WebDriver instance with the specified service and options
window = webdriver.Chrome(service=service, options=chrome_options)

# Navigate to the Bing.com website
window.get("https://www.bing.com/")

# Retrieve the page title
title = window.title

# Print the page title
print(title)

Tag summary

Content type

Image

Digest

sha256:05fdc87fb…

Size

722.7 MB

Last updated

over 2 years ago

docker pull cheng3969/selenium:2.0