【问题标题】:parse/iterate html source code to get to a certain file with wget only解析/迭代 html 源代码以仅使用 wget 获取某个文件
【发布时间】:2017-06-05 13:08:11
【问题描述】:

好的,所以这可能已经被问过了,但是经过几个小时的搜索,我没有找到任何可行的方法,所以......

假设有一个名为index.html 的页面,其中包含多个指向不同页面的超链接。 这些页面包含要下载的文件。

例如

<!-- index.html -->
...
<a href="page1.html">1</a>
<a href="page2.html">2</a>
<a href="page3.html">3</a>
...

第 1 页可能如下所示

<!-- page1.html -->
...
<a href="page1file.pdf">Download</a>
...

现在我想下载所有*.pdf 文件。是否有可能仅使用 wget 执行此操作,还是我需要为此创建一个脚本?

提前谢谢你。

【问题讨论】:

  • 我们可以说每个文件都可以使用以下 URL 语法下载:pageX.html/pageXfile.pdf 吗?
  • 遗憾的是没有。文件名在每种情况下都是唯一的。

标签: html bash recursion scripting wget


【解决方案1】:

不确定是否只能使用 wget,但这个循环应该可以做到:

for i in $(grep "^<a" index.html | cut -d'"' -f2); do file=$(grep "^<a" $i | cut -d'"' -f2); wget $i/$file ; done

【讨论】:

    猜你喜欢
    • 2011-10-11
    • 2012-04-30
    • 1970-01-01
    • 2012-01-18
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多