一、docker-compose

services:
  chrome:
    image: selenium/node-chrome:4.6.0-20221104
    shm_size: 2gb  # 设置共享内存,官方建议值,避免浏览器引起容器崩溃
    depends_on:    # 设置依赖关系
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  firefox:
    image: selenium/node-firefox:4.6.0-20221104
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  selenium-hub:
    image: selenium/hub:4.6.0-20221104
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

docker 创建好 selenium 后,debian 开启了 4444 端口
问题一
用 IP:4444 访问打不开。NGINX 代理
server {
listen 80;
server_name selenium.hhh.cn;

location / {
proxy_pass http://ip+端口;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
代理过后就可以打开了

二、windows 本地使用

chrome_options = self._get_option(browser="chrome", is_remote=True)
url = remote_server_ip
if remote_server_port:
    url += f':{remote_server_port}'
driver = webdriver.Remote(
    # command_executor=f'http://{url}/wd/executor',
    command_executor=f'http://{url}/wd/hub',
    # command_executor=f'http://{url}',
    # command_executor=f'http://{url}',
    options=chrome_options
)
self._web_driver = driver

问题二:command_executor 的值是否正确

虽然调用,但是报错


↙↙↙阅读原文可查看相关链接,并与作者交流