简体   繁体   English

如何使用 docker-compose 在容器中保存来自 selenium webdriver 的文件?

[英]How can I save file from selenium webdriver in conteiner using docker-compose?

I try to save same files from site using selenium whith docker-compose.我尝试使用 selenium 和 docker-compose 从站点保存相同的文件。 When i do.click() on link to downloads file, it mast saved in container /home/seluser/Downloads but when i try to mount values to save files in host: -./app/down:/home/seluser/Downloads当我 do.click() 链接到下载文件时,它保存在容器 /home/seluser/Downloads 中,但是当我尝试挂载值以将文件保存在主机中时:-./app/down:/home/seluser/Downloads
it only erases all in folder Downloads in selenium container and while the program is running no files appear in container /home/seluser/Downloads, but without definition volumes all files appear normally in conainer.它只会擦除 selenium 容器中的文件夹 Downloads 中的所有内容,并且在程序运行时,容器 /home/seluser/Downloads 中没有文件出现,但没有定义卷,所有文件都正常出现在容器中。

alex@alex-Aspire-E1-571G:~/documents/python/yahoo_script/app$ docker ps
CONTAINER ID   IMAGE                        COMMAND                  CREATED          STATUS          PORTS                                       NAMES
aebf66508644   yahoo_script_app             "sh -c 'python3 main…"   32 seconds ago   Up 28 seconds                                               yahoo_script_app_1
16ad4ae3ddb0   selenium/standalone-chrome   "/opt/bin/entry_poin…"   34 seconds ago   Up 31 seconds   0.0.0.0:4444->4444/tcp, :::4444->4444/tcp   yahoo_script_selenium_1
alex@alex-Aspire-E1-571G:~/documents/python/yahoo_script/app$ docker exec -it 16 /bin/sh
$ cd home/seluser/Downloads
$ ls
PD.csv  PINS.csv  ZUO.csv

My Dockerfile:我的 Dockerfile:

FROM python:3.8
ENV PYTHONUNBUFFERED 1
RUN pip install --upgrade pip
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
COPY ./app /app
WORKDIR /app

My docker-compose.yml我的 docker-compose.yml

version: "3"

services:
  selenium:
    image: selenium/standalone-chrome
    volumes:
      - ./app/down:/home/seluser/Downloads
    ports:
    - 4444:4444
    restart: always

  app:
    build:
      context: .
    volumes:
    - ./app:/app
    command: sh -c "python3 main.py"
    depends_on:
      - selenium

And code:和代码:

    options = webdriver.ChromeOptions()
    options.headless = True
    options.add_argument("--no-sandbox")
    options.add_argument('--disable-blink-features=AutomationControlled')
    prefs = {'download.default_directory': f'/home/seluser/Downloads',
             "directory_upgrade": True,
             "safebrowsing.enabled": True
             }
    options.add_experimental_option('prefs', prefs)
    capabilities = {
        "browserName": "chrome",
        "version": "90.0.4430.85",
        "platform": "LINUX"
    }
    driver = webdriver.Remote('http://selenium:4444/wd/hub', desired_capabilities=capabilities, options=options)

How can I have files from container to host?如何将文件从容器传输到主机?

I find answer in Prompt_for_download is still appearing after setting false in prefs Main thing is what我发现Prompt_for_download 中的答案在 prefs 中设置 false 后仍然出现主要是什么
Aside from that, make sure directory exists and there are permissions to write into it.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium docker-compose 下载文件 - Selenium docker-compose download file 我无法使用 docker-compose Dockerize MySQL 和 Django App - I can not Dockerize MySQL and Django App using docker-compose 如何从docker-compose安装requirements.txt? - How can I install requirements.txt from docker-compose? Docker 无法打开文件以在使用 django 的容器中运行 python 应用程序,使用 ZBAEDB53E845AE71F13945FCC00572 - Docker can't open file to run the python application in a container with django using docker-compose 如何在 Linux 服务器上使用 docker-compose 安装 phantomjs 和 selenium? - How to install phantomjs and selenium with docker-compose on linux server? 使用docker-compose up与docker-compose run从容器内部执行容器中的命令 - executing commands in containers from within a container using docker-compose up vs docker-compose run Docker-compose 文件配置 - Docker-compose file configuration 如何以与 docker-compose 相同的方式在远程服务器上运行 Docker 容器? - How can I run a Docker container on a remote server in the same manner as docker-compose up? 在docker-compose中运行python selenium - running python selenium in docker-compose docker-compose exec导致[Errno 2]没有此类文件或目录:docker容器中的'docker-compose':'docker-compose' - docker-compose exec causes [Errno 2] No such file or directory: 'docker-compose': 'docker-compose' in docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM