Sign inSign up

chiupam/selenium

By chiupam

•Updated almost 5 years ago

CentOS8 + Python3.6.8 + selenium + chrome +chromedriver

Image
2

878

chiupam/selenium repository overview

⁠简介

使用 centos8 为基础镜像制作的自定义镜像,内置 python 3.6.8、pip3、selenium、requests、chrome、chromedriver 及 crontabs 服务,方便调试使用 python3 + selenium + chrome + chromedriver 的脚本。

⁠目录树

/data/
  `-- example.py

⁠新建容器

docker run -dit \
  -v $PWD:/data \
  --name selenium \
  --restart always \
  chiupam/selenium:latest

⁠进入容器

docker exec -it selenium bash

⁠容器内命令

⁠python

python example.py

⁠pip

pip freeze

⁠crontab

crontab -l # 列出定时任务
crontab -e # 修改定时任务
crontab -r # 清空定时任务
crontab <file path> # 把文件内容写入crontab定时任务蹱

⁠示例脚本

# coding=utf-8
from selenium import webdriver  # 必须


def main():
    driver.get('https://www.baidu.com/')
    print(driver.title)
    driver.quit()


if __name__ == "__main__":
    chrome_options = webdriver.ChromeOptions()  # 必须
    chrome_options.add_argument('--headless')  # 必须
    chrome_options.add_argument('--no-sandbox')  # 必须
    chrome_options.add_argument('--windows-size=1920, 1080')  # 建议
    driver = webdriver.Chrome(options=chrome_options)  # 必须
    main()

⁠示例定时

# 每天12点自动执行一次/data/example.py脚本
0 0 * * * cd /data && python3 example.py >>/data/example.log 2>&1 &

Tag summary

Content type

Image

Digest

Size

810.2 MB

Last updated

almost 5 years ago

docker pull chiupam/selenium