Python 在Docker容器中使用Selenium Chrome驱动程序进行Flask API Web刮片

Python 在Docker容器中使用Selenium Chrome驱动程序进行Flask API Web刮片,python,docker,selenium,flask,Python,Docker,Selenium,Flask,Selenium Grid Server在端口4444上工作,我希望为FlaskAPI提供另一个容器,该容器将使用Selenium Chrome驱动程序来抓取网站 Flask API在Docker容器外部工作,但当我构建Docker容器时,它会给出urllib3异常: urllib3.exceptions.MaxRetryError urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=4444):

Selenium Grid Server在端口4444上工作,我希望为FlaskAPI提供另一个容器,该容器将使用Selenium Chrome驱动程序来抓取网站

Flask API在Docker容器外部工作,但当我构建Docker容器时,它会给出urllib3异常:

urllib3.exceptions.MaxRetryError
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=4444): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd542587760>: Failed to establish a new connection: [Errno 111] Connection refused'))
烧瓶API:

docker run -d -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm selenium/standalone-chrome-debug:3.141.59-yttrium
从selenium导入webdriver
从selenium.webdriver导入DesiredCapabilities
从烧瓶进口烧瓶
app=烧瓶(名称)
@应用程序路径(“/”)
def title():
driver=webdriver.Remote(“http://127.0.0.1:4444/wd/hub“,DesiredCapabilities.CHROME)
驱动程序。获取(“http://www.python.org")
驱动程序关闭()
返回驱动程序名称
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
app.run(host=“0.0.0.0”,端口=3000,调试=True,使用\u重载器=True)
Dockerfile

FROM ubuntu:latest

RUN apt-get update && apt-get upgrade -y && apt-get clean
RUN apt-get install -y curl python3.8 python3.8-dev python3.8-distutils
RUN curl -s https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
    python3 get-pip.py --force-reinstall && \
    rm get-pip.py
RUN pip3 install -U selenium

RUN apt-get update -y


WORKDIR /app

COPY . /app

RUN pip3 --no-cache-dir install -r requirements.txt

EXPOSE 3000

ENTRYPOINT  ["python3"]

CMD ["app.py"]

您的容器似乎没有Internet访问权限。您有解决方案吗?此问题似乎已解决。我认为Internet似乎正在工作,因为如果我“获得更新”,容器内会发生bash它获取并读取包。您的容器似乎没有Internet访问权限。您有解决方案吗?此问题似乎已解决。我认为Internet似乎正在工作,因为在容器内,如果我“apt get update”,它将获取并读取包。