【发布时间】:2017-12-06 17:17:16
【问题描述】:
我运行一个 python webscraper 从各种网站收集文章,然后将其保存为 csv 文件。我一直在手动运行这些,但最近一直在尝试在 google cloud shell 中运行它们。我在依赖关系方面遇到了一些问题,所以我决定构建一个 docker 映像来运行我的 python 刮板
到目前为止,我已经成功创建了一个 Dockerfile,用于构建具有所有必要依赖项的容器。
FROM python:3
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
RUN pip install lxml
COPY Fin24 ./Fin24
COPY scraped_list.csv ./scraped_list.csv
# Run fin24.py when the container launches
CMD ["python3", "fin24.py"]
fin24.py 包含我的刮板。 Fin24 是一个 txt 文件,其中包含我的爬虫在进入每篇文章并提取内容之前为文章链接爬取的所有基本 URL。 scraped_list.csv 包含我之前抓取的所有网站,我的 python 脚本会检查这些网站以确保我不会再次抓取同一篇文章。
运行上述后,我可以看到它有效。 python 脚本在它找到的所有网站都被抓取后停止。但是,我猜它正在将 csv 文件(输出)保存在 docker 容器中。我怎样才能把它保存到我正在运行 docker 的目录中?
最终我想简单地将 Dockerfile 上传到我的 Google 云 shell,并将其作为 cronjob 运行,并将所有输出保存在 shell 中。任何帮助将不胜感激
【问题讨论】:
-
你在看还是 VOLUME 命令? docs.docker.com/engine/reference/builder/#volume
标签: python docker web-scraping google-cloud-shell