wget 命令下载 web-page 并用 html 标题重命名文件?
wget command to download web-page & rename file with with html title?
我想下载 html web-page 并将文件名设为 html 页面的标题。
我找到了获取 html 标题的命令:
wget -qO- 'https://www.linuxinsider.com/story/Austrumi-Linux-Has-Great-Potential-if-You-Speak-Its-Language-86285.html/' | gawk -v IGNORECASE=1 -v RS='</title' 'RT{gsub(/.*<title[^>]*>/,"");print;exit}'
它会打印:Austrumi Linux 如果你说它的语言,它就有很大的潜力 |评论 | Linux内幕
发现于:https://unix.stackexchange.com/questions/103252/how-do-i-get-a-websites-title-using-command-line
在下载 web-page 时,我如何将标题传送回 wget 以将其用作文件名?
编辑:如果无法直接在 wget 中执行此操作,我找到了一种方法,可以在下载后简单地重命名 html 文件
Renaming HTML files using <title> tags
您不能 wget 一个文件,分析它的内容,然后使下载该文件的同一 wget 执行神奇地回到过去,并将它输出到一个以您在步骤 2 中分析的内容命名的新文件。只需这样做:
wget '...' > tmp &&
name=$(gawk '...' tmp) &&
mv tmp "$name"
根据需要在 name
中添加针对 /
的保护。
我想下载 html web-page 并将文件名设为 html 页面的标题。
我找到了获取 html 标题的命令:
wget -qO- 'https://www.linuxinsider.com/story/Austrumi-Linux-Has-Great-Potential-if-You-Speak-Its-Language-86285.html/' | gawk -v IGNORECASE=1 -v RS='</title' 'RT{gsub(/.*<title[^>]*>/,"");print;exit}'
它会打印:Austrumi Linux 如果你说它的语言,它就有很大的潜力 |评论 | Linux内幕
发现于:https://unix.stackexchange.com/questions/103252/how-do-i-get-a-websites-title-using-command-line
在下载 web-page 时,我如何将标题传送回 wget 以将其用作文件名?
编辑:如果无法直接在 wget 中执行此操作,我找到了一种方法,可以在下载后简单地重命名 html 文件
Renaming HTML files using <title> tags
您不能 wget 一个文件,分析它的内容,然后使下载该文件的同一 wget 执行神奇地回到过去,并将它输出到一个以您在步骤 2 中分析的内容命名的新文件。只需这样做:
wget '...' > tmp &&
name=$(gawk '...' tmp) &&
mv tmp "$name"
根据需要在 name
中添加针对 /
的保护。