在 Docker 和 Python3.10 容器中收到此错误
示例链接如下:https://finance.yahoo.com/quote/BABA/options?p=BABA&date=1653004800
Browser closed unexpectedly:
这是我的 Dockerfile
FROM python:3.10
RUN apt-get update
# TA-Lib
RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \
tar -xvzf ta-lib-0.4.0-src.tar.gz && \
cd ta-lib/ && \
./configure && \
make && \
make install && \
cd .. && \
rm -R ta-lib ta-lib-0.4.0-src.tar.gz
COPY requirements.txt /tmp/
COPY data/stocks.csv /tmp/data/stocks.csv
RUN pip install --requirement /tmp/requirements.txt
RUN pip freeze >> /tmp/requirement.txt
RUN pyppeteer-install
CMD ["python", "/tmp/app.py"]
async def async_get_options_chain(ticker, date=None, raw=True, headers={'User-agent': 'Mozilla/5.0'}):
"""Extracts call / put option tables for input ticker and expiration date. If
no date is input, the default result will be the earliest expiring
option chain from the current date.
@param: ticker
@param: date"""
site = options.build_options_url(ticker, date)
browser = await launch({'headless': True, 'options': {'args': ['--no-sandbox', '--disable-setuid-sandbox']}})
page = await browser.newPage()
await page.goto(site)
content = await page.evaluate('document.body.textContent', force_expr=True)
解决这个问题的方法似乎不是从软件包安装,而是从 Dockerfile 安装。现在我必须解决超时问题:)
Dockerfile
# Pyppeteer
RUN apt-get update && apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
--no-install-recommends \
&& curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update && apt-get install -y \
google-chrome-stable \
--no-install-recommends
# It won't run from the root user.
RUN groupadd chrome && useradd -g chrome -s /bin/bash -G audio,video chrome \
&& mkdir -p /home/chrome && chown -R chrome:chrome /home/chrome
Python
browser = await launch(executablePath='/usr/bin/google-chrome-stable', headless=True, args=['--no-sandbox'])
我遇到了同样的问题,为我解决的确实是docker文件没有正确的要求,而且,当我构建Docker时,我需要添加
--platform=linux/amd64
。我正在 MB 16" M1 芯片上运行。
## To run Pyppeteer and chromium
RUN apt-get install -y gconf-service \
libasound2 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
ca-certificates \
fonts-liberation \
libappindicator1 \
libnss3 \
lsb-release \
xdg-utils \
wget \
libcairo-gobject2 \
libxinerama1 \
libgtk2.0-0 \
libpangoft2-1.0-0 \
libthai0 \
libpixman-1-0 \
libxcb-render0 \
libharfbuzz0b \
libdatrie1 \
libgraphite2-3 \
libgbm1
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/chrome.list
当我构建 Docker 时,我添加
--platform=linux/amd64
就像
docker build -f Dockerfile . -t docker-tag --platform=linux/amd64
请参阅此处的 dockerfile、compose 和 python 提取对我有用的内容:https://github.com/pyppeteer/pyppeteer/issues/194#issuecomment-1882326467