【问题标题】:Use wget to make static copy of site with image redirects使用 wget 通过图像重定向制作站点的静态副本
【发布时间】:2019-12-22 17:37:50
【问题描述】:

我想使用 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 的免费计划。

【问题讨论】:

  • wget -P ./test/ -mpck --user-agent="" -e robots=off --wait 1 -E http://activestorage-test.herokuapp.com/怎么样
  • 感谢@Davebra,您的评论让我走上了正轨!

标签: ruby-on-rails-5 wget rails-activestorage ruby-on-rails-6


【解决方案1】:

这是使它起作用的选项组合:

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

说明:

(取自here

-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 活动存储目录方案中,例如:

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

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

【讨论】:

    猜你喜欢
    • 2018-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    相关资源
    最近更新 更多