标签:mes 构建 int 配置 yml volume mamicode coding 命名
(我这因为已经拉取过了哈)
version: "2.0"
services:
python:
image: selenium_python:v1
volumes:
- ./baidu.py:/root/baidu.py # 将本地文件映射到容器内,前面的路径是本机的,后面的是容器的。注意:可以指定具体文件,也可以指定路径
command: python /root/baidu.py # 定义启动容器执行的命令
depends_on:
- chrome #映射的域名,脚本中要把域名改成这个
chrome:
image: selenium/standalone-chrome:latest
ports:
- "4444:4444"
shm_size: 2g

修改脚本,上篇文章中的脚本,稍微改下:

# /usr/bin/bash python
# -*- coding:utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
time.sleep(5)
driver = webdriver.Remote(
command_executor="http://chrome:4444/wd/hub",
desired_capabilities=DesiredCapabilities.CHROME
)
driver.get("https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=baidu&wd=%E5%A5%B3%E7%A5%9E%E8%8A%82%E5%BF%AB%E4%B9%90&oq=iPad%25E7%2594%25BB%25E6%25B0%25B4%25E5%25BD%25A9&rsv_pq=da863c960031fa89&rsv_t=320bU5S7GOOB43J2GLgjE66RWcLR2giCuNktmA5I6Wm7VcW7dZ1It2hKWxs&rqlang=cn&rsv_enter=1&rsv_dl=tb&inputT=8595&rsv_sug3=16&rsv_sug1=14&rsv_sug7=101&rsv_sug2=0&rsv_sug4=11686")
content = driver.title.split("_")[0]
print(content)
driver.close()
如果没出现上面的,那就会出现名场面了:
虽然绿了,但也不确定是不是真的搞定了撒,查看下日志:

在docker容器中部署python-selenium+chrome-headless自动化脚本(续)
标签:mes 构建 int 配置 yml volume mamicode coding 命名
原文地址:https://www.cnblogs.com/mikasama/p/12494345.html