如何将Wget名称文件作为URL的一部分?

时间:2015-06-28 16:07:43

标签: regex sed web-crawler wget

短篇小说:

我希望Wget命名下载的文件,因为它们匹配正则表达式标记([^/]*)

wget -r --accept-regex="^.*/([^/]*)/$" $MYURL

全文:

我使用GNU Wget以递归方式下载特定WordPress网站下的一个特定文件夹。我使用正则表达式只接受帖子,没有别的。以下是我如何使用它:

wget -r --accept-regex="^.*/([^/]*)/$" $MYURL

它可以工作,Wget会跟随所有想要的网址。但是,它会将文件保存为.../last_directory/index.html,但我希望将这些文件保存为last_directory.html.html部分是可选的)。

有没有办法单独使用Wget?或者您会建议如何使用sed或类似工具做同样的事情?

1 个答案:

答案 0 :(得分:1)

你可以使用sed。

wget -r --accept-regex="^.*/([^/]*)/$" $MYURL |  sed 's~\(.*\)/[^.]*~\1~'

示例:

$ echo '/foo/last_directory/index.html' | sed 's~\(.*\)/[^.]*~\1~'
/foo/last_directory.html