100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Docker selenium自动化 - Python调用容器实例跑自动化查天气实例演示 docker sel

Docker selenium自动化 - Python调用容器实例跑自动化查天气实例演示 docker sel

时间:2021-01-18 10:05:55

相关推荐

Docker selenium自动化 - Python调用容器实例跑自动化查天气实例演示 docker sel

Docker selenium自动化 - 环境部署与 Python 自动化运行实战演示

第一章:docker selenium 环境部署① 下载 selenium 镜像② 容器 selenium 实例的创建与运行③ 浏览器访问 selenium Grid④ docker 命令大全第二章:Python 调用 docker selenium 执行自动化实例演示① 源码展示② 运行效果

[系列文章篇]

篇章一:Docker selenium自动化 -windowsdocker的安装与运行环境检测

[问题处理篇]

篇章一:Docker selenium自动化 - 修改/dev/shm路径大小实例演示,“session deleted because of page crash”问题解决

第一章:docker selenium 环境部署

① 下载 selenium 镜像

首先拉取selenium/hub镜像。

执行命令:docker pull selenium/hub

然后拉取selenium/node-chrome镜像。

执行命令:docker pull selenium/node-chrome

docker images查看容器镜像。

② 容器 selenium 实例的创建与运行

创建容器实例:

docker run -d -P --name=hub selenium/hub

docker run -d -P --link=hub:hub selenium/node-chrome

查看当前运行的容器实例:

docker ps

查看所有的容器实例:

docker ps -a

可以通过docker start/stop 实例名来启动停用容器实例。

一般服务器重启后,就需要来启动容器了。

③ 浏览器访问 selenium Grid

docker ps可以查看生成的端口,通过本地ip + 端口号即可访问selenium Grid控制台。

可以看到浏览器版本相关信息。

可以看到相关配置信息。

④ docker 命令大全

docker相关命令

docker --helpUsage: docker [OPTIONS] COMMANDA self-sufficient runtime for containersOptions:--config stringLocation of client config files (default"C:\\Users\\Administrator\\.docker")-c, --context stringName of the context to use to connect to thedaemon (overrides DOCKER_HOST env var anddefault context set with "docker context use")-D, --debug Enable debug mode-H, --host listDaemon socket(s) to connect to-l, --log-level string Set the logging level("debug"|"info"|"warn"|"error"|"fatal")(default "info")--tlsUse TLS; implied by --tlsverify--tlscacert string Trust certs signed only by this CA (default"C:\\Users\\Administrator\\.docker\\ca.pem")--tlscert stringPath to TLS certificate file (default"C:\\Users\\Administrator\\.docker\\cert.pem")--tlskey stringPath to TLS key file (default"C:\\Users\\Administrator\\.docker\\key.pem")--tlsverifyUse TLS and verify the remote-v, --version Print version information and quitManagement Commands:builderManage buildsbuildx*Build with BuildKit (Docker Inc., v0.6.3)compose* Docker Compose (Docker Inc., v2.0.0)configManage Docker configscontainer Manage containerscontextManage contextsimage Manage imagesmanifest Manage Docker image manifests and manifest listsnetworkManage networksnode Manage Swarm nodespluginManage pluginsscan* Docker Scan (Docker Inc., v0.8.0)secretManage Docker secretsserviceManage servicesstack Manage Docker stacksswarm Manage SwarmsystemManage Dockertrust Manage trust on Docker imagesvolumeManage volumesCommands:attachAttach local standard input, output, and error streams to a running containerbuild Build an image from a DockerfilecommitCreate a new image from a container's changescpCopy files/folders between a container and the local filesystemcreateCreate a new containerdiff Inspect changes to files or directories on a container's filesystemeventsGet real time events from the serverexec Run a command in a running containerexportExport a container's filesystem as a tar archivehistoryShow the history of an imageimagesList imagesimportImport the contents from a tarball to create a filesystem imageinfo Display system-wide informationinspectReturn low-level information on Docker objectskill Kill one or more running containersload Load an image from a tar archive or STDINlogin Log in to a Docker registrylogoutLog out from a Docker registrylogs Fetch the logs of a containerpause Pause all processes within one or more containersport List port mappings or a specific mapping for the containerpsList containerspull Pull an image or a repository from a registrypush Push an image or a repository to a registryrenameRename a containerrestartRestart one or more containersrmRemove one or more containersrmi Remove one or more imagesrun Run a command in a new containersave Save one or more images to a tar archive (streamed to STDOUT by default)searchSearch the Docker Hub for imagesstart Start one or more stopped containersstats Display a live stream of container(s) resource usage statisticsstop Stop one or more running containerstag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGEtop Display the running processes of a containerunpauseUnpause all processes within one or more containersupdateUpdate configuration of one or more containersversionShow the Docker version informationwait Block until one or more containers stop, then print their exit codesRun 'docker COMMAND --help' for more information on a command.To get more help with docker, check out our guides at /go/guides/

docker run相关命令

docker run --helpUsage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]Run a command in a new containerOptions:--add-host list Add a custom host-to-IP mapping(host:ip)-a, --attach listAttach to STDIN, STDOUT or STDERR--blkio-weight uint16 Block IO (relative weight),between 10 and 1000, or 0 todisable (default 0)--blkio-weight-device list Block IO weight (relative deviceweight) (default [])--cap-add list Add Linux capabilities--cap-drop list Drop Linux capabilities--cgroup-parent string Optional parent cgroup for thecontainer--cgroupns stringCgroup namespace to use(host|private)'host': Run the container inthe Docker host's cgroup namespace'private': Run the container inits own private cgroup namespace'': Use the cgroupnamespace as configured by thedefault-cgroupns-modeoption on the daemon (default)--cidfile string Write the container ID to the file--cpu-period int Limit CPU CFS (Completely FairScheduler) period--cpu-quota int Limit CPU CFS (Completely FairScheduler) quota--cpu-rt-period int Limit CPU real-time period inmicroseconds--cpu-rt-runtime int Limit CPU real-time runtime inmicroseconds-c, --cpu-shares int CPU shares (relative weight)--cpus decimal Number of CPUs--cpuset-cpus string CPUs in which to allow execution(0-3, 0,1)--cpuset-mems string MEMs in which to allow execution(0-3, 0,1)-d, --detachRun container in background andprint container ID--detach-keys string Override the key sequence fordetaching a container--device listAdd a host device to the container--device-cgroup-rule list Add a rule to the cgroup alloweddevices list--device-read-bps list Limit read rate (bytes per second)from a device (default [])--device-read-iops listLimit read rate (IO per second)from a device (default [])--device-write-bps listLimit write rate (bytes persecond) to a device (default [])--device-write-iops list Limit write rate (IO per second)to a device (default [])--disable-content-trustSkip image verification (default true)--dns list Set custom DNS servers--dns-option listSet DNS options--dns-search listSet custom DNS search domains--domainname string Container NIS domain name--entrypoint string Overwrite the default ENTRYPOINTof the image-e, --env list Set environment variables--env-file list Read in a file of environment variables--expose listExpose a port or a range of ports--gpus gpu-requestGPU devices to add to thecontainer ('all' to pass all GPUs)--group-add list Add additional groups to join--health-cmd string Command to run to check health--health-interval duration Time between running the check(ms|s|m|h) (default 0s)--health-retries int Consecutive failures needed toreport unhealthy--health-start-period duration Start period for the container toinitialize before startinghealth-retries countdown(ms|s|m|h) (default 0s)--health-timeout duration Maximum time to allow one check torun (ms|s|m|h) (default 0s)--help Print usage-h, --hostname stringContainer host name--init Run an init inside the containerthat forwards signals and reapsprocesses-i, --interactiveKeep STDIN open even if not attached--ip string IPv4 address (e.g., 172.30.100.104)--ip6 string IPv6 address (e.g., 2001:db8::33)--ipc string IPC mode to use--isolation stringContainer isolation technology--kernel-memory bytes Kernel memory limit-l, --label list Set meta data on a container--label-file listRead in a line delimited file of labels--link list Add link to another container--link-local-ip list Container IPv4/IPv6 link-localaddresses--log-driver string Logging driver for the container--log-opt list Log driver options--mac-address string Container MAC address (e.g.,92:d0:c6:0a:29:33)-m, --memory bytes Memory limit--memory-reservation bytes Memory soft limit--memory-swap bytes Swap limit equal to memory plusswap: '-1' to enable unlimited swap--memory-swappiness intTune container memory swappiness(0 to 100) (default -1)--mount mountAttach a filesystem mount to thecontainer--name stringAssign a name to the container--network networkConnect a container to a network--network-alias list Add network-scoped alias for thecontainer--no-healthcheck Disable any container-specifiedHEALTHCHECK--oom-kill-disableDisable OOM Killer--oom-score-adj int Tune host's OOM preferences (-1000to 1000)--pid string PID namespace to use--pids-limit int Tune container pids limit (set -1for unlimited)--platform stringSet platform if server ismulti-platform capable--privileged Give extended privileges to thiscontainer-p, --publish list Publish a container's port(s) tothe host-P, --publish-allPublish all exposed ports torandom ports--pull stringPull image before running("always"|"missing"|"never")(default "missing")--read-only Mount the container's rootfilesystem as read only--restart string Restart policy to apply when acontainer exits (default "no")--rm Automatically remove the containerwhen it exits--runtime string Runtime to use for this container--security-opt list Security Options--shm-size bytes Size of /dev/shm--sig-proxy Proxy received signals to theprocess (default true)--stop-signal string Signal to stop a container(default "15")--stop-timeout intTimeout (in seconds) to stop acontainer--storage-opt listStorage driver options for thecontainer--sysctl map Sysctl options (default map[])--tmpfs list Mount a tmpfs directory-t, --tty Allocate a pseudo-TTY--ulimit ulimit Ulimit options (default [])-u, --user stringUsername or UID (format:<name|uid>[:<group|gid>])--userns string User namespace to use--uts string UTS namespace to use-v, --volume listBind mount a volume--volume-driver string Optional volume driver for thecontainer--volumes-from list Mount volumes from the specifiedcontainer(s)-w, --workdir string Working directory inside the container

第二章:Python 调用 docker selenium 执行自动化实例演示

① 源码展示

# -*- coding: UTF8 -*-# .11.16# 小蓝枣# docker selenium 自动化from selenium import webdriverfrom time import sleepdriver = webdriver.Remote(command_executor='http://127.0.0.1:55006/wd/hub',desired_capabilities={'browserName': 'chrome'})try:# 登录中国气象网查看北京天气driver.get('/weather1d/101010100.shtml')sleep(3)# 读取天气信息bj_temperature = driver.find_element_by_xpath('//*[@class="sk mySkyNull"]//*[@class="tem"]/*').textbj_wind_direction = driver.find_element_by_xpath('//*[@class="sk mySkyNull"]//*[@class="zs w"]/span').textbj_wind_class = driver.find_element_by_xpath('//*[@class="sk mySkyNull"]//*[@class="zs w"]/em').textbj_air_quality = driver.find_element_by_xpath('//*[@class="sk mySkyNull"]//*[@class="zs pol"]//a').textbj_weather = '''城市:北京当前温度:%s风向:%s风力:%s空气质量:%s'''%(bj_temperature,bj_wind_direction,bj_wind_class,bj_air_quality)# 打印抓取的天气信息print(bj_weather)# 保存截图driver.get_screenshot_as_file("docker_selenium_run_001.png")# 保证出错后进程正常释放finally:driver.quit()

② 运行效果

抓取的天气信息如下:

同时可以看到保存的截图。

喜欢的点个赞❤吧!

Docker selenium自动化 - Python调用容器实例跑自动化查天气实例演示 docker selenium自动化环境部署过程

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。