带有 python3、chromedriver、chrome & 的 Docker 镜像硒
问题描述
我的目标是使用由 Selenium 抓取网络.python.org/" rel="noreferrer">Python 来自 docker 容器.
我四处寻找并没有找到安装了以下所有内容的 docker 映像:
- Python 3
- ChromeDriver
- Chrome
- 硒
是否有人可以将我链接到 docker image 与所有这些已安装并一起工作?
也许建立我自己的并没有我想象的那么困难,但到目前为止它已经暗示了我.
任何和所有建议都表示赞赏.
解决方案试试https://github.com/SeleniumHQ/docker-selenium.
它已经安装了python:
$ docker run selenium/standalone-chrome python3 --versionPython 3.5.2
说明表明您开始使用它
docker run -d -p 4444:4444 --shm-size=2g selenium/standalone-chrome
要允许 selenium 通过 python 运行,您似乎需要安装软件包.创建这个 Dockerfile
:
来自 selenium/standalone-chrome用户根运行 wget https://bootstrap.pypa.io/get-pip.py运行 python3 get-pip.py运行 python3 -m pip install selenium
然后你可以运行它
docker 构建.-t 硒铬 &&docker run -it selenium-chrome python3
与普通的 python
docker 镜像相比,优势在于您不需要安装 chromedriver 本身,因为它来自 selenium/standalone-chrome
.p>
My objective is to scrape the web with Selenium driven by Python from a docker container.
I've looked around for and not found a docker image with all of the following installed:
- Python 3
- ChromeDriver
- Chrome
- Selenium
Is anyone able to link me to a docker image with all of these installed and working together?
Perhaps building my own isn't as difficult as I think, but it's alluded me thus far.
Any and all advice appreciated.
解决方案Try https://github.com/SeleniumHQ/docker-selenium.
It has python installed:
$ docker run selenium/standalone-chrome python3 --version
Python 3.5.2
The instructions indicate you start it with
docker run -d -p 4444:4444 --shm-size=2g selenium/standalone-chrome
Edit:
To allow selenium to run through python it appears you need to install the packages. Create this Dockerfile
:
FROM selenium/standalone-chrome
USER root
RUN wget https://bootstrap.pypa.io/get-pip.py
RUN python3 get-pip.py
RUN python3 -m pip install selenium
Then you could run it with
docker build . -t selenium-chrome &&
docker run -it selenium-chrome python3
The advantage compared to the plain python
docker image is that you won't need to install the chromedriver itself since it comes from selenium/standalone-chrome
.
相关文章