首页 > 解决方案 > 使用 wget 通过图像重定向制作站点的静态副本

问题描述

我想使用 wget 创建动态站点的静态副本。图像到达控制器,然后被重定向到它们的真实(过期)URL。我正在努力寻找适用于wget. 我试过

wget \
--page-requisites --convert-links --max-redirect=10 \
http://activestorage-test.herokuapp.com

但图像路径未正确处理。

这是可行的吗?如果可行 - 怎么做?

背景

该站点是使用 Ruby on Rails 6 创建的。该站点上的图像是使用 Active Storage 上传的,因此浏览器会遇到 rails 控制器并在获取它们时被重定向。

例子

如果你能告诉我一种wget用来获取静态副本的方法

activestorage-test.herokuapp.com

包括照片我的问题就解决了。重定向图像的随机图像名称是可以的,并且可能是必要的。

该应用程序可能需要一些时间来启动,因为它是 Heroku 的免费计划。

标签: ruby-on-rails-5wgetrails-activestorageruby-on-rails-6

解决方案


这是使其工作的选项组合:

wget -mk http://activestorage-test.herokuapp.com

说明:

(取自这里

-m
--mirror
    Turn on options suitable for mirroring.  This option turns on recursion and time-stamping, sets
    infinite recursion depth and keeps FTP directory listings.  It is currently equivalent to -r -N -l
    inf --no-remove-listing.

-k
--convert-links
    After the download is complete, convert the links in the document to make them suitable for local
    viewing.  This affects not only the visible hyperlinks, but any part of the document that links to
    external content, such as embedded images, links to style sheets, hyperlinks to non-HTML content,
    etc.
    ...

这将使图像在 rails active storage dir 方案中存储为纯文本文件,例如:

├── rails
│   └── active_storage
│       └── representations
│           └── eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBLQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--192401464645b8679e8fc4b8b8e7423923a4404b
│               └── eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9MY21

该答案基于@Davebra 的评论,但删除了与问题无关的所有选项。


推荐阅读