[英]uncompress html source code using terminal
some website source code is compressed and in one line.一些网站源代码被压缩并在一行中。 which i want in default HTML structured.
我想要的默认 HTML 结构。 Can i do with terminal?
我可以用终端吗? I want to do it with wget command.
我想用 wget 命令来做。 i use online tool textFixer.
我使用在线工具 textFixer。 But i want to do it with terminal.
但我想用终端来做。
i want one line text into default HTML structure using terminal or using script.我想使用终端或使用脚本将一行文本转换为默认的 HTML 结构。
http://www.sawfirst.com/ http://www.sawfirst.com/
is example of one line compressed source code.是一行压缩源代码的示例。
i want to one line source code to default HTML structured.我想要一行源代码到默认的 HTML 结构化。
if you are able to utilize php you could do something like如果您能够使用 php,您可以执行类似的操作
curl URL | php -r '$s = ""; while($l = fgets(STDIN)) {$s .= $l;} $x=new DOMDocument(); $x->loadHTML($s); $x->preserveWhiteSpace = false; $x->formatOutput = true; echo $x->saveHTML();'
saveHTML seems to not insert leading white spaces (for improved indentation), but saveXML does, so you can use $x->saveXML() instead. saveHTML 似乎不会插入前导空格(为了改进缩进),但 saveXML 会插入,因此您可以使用 $x->saveXML() 代替。
That will most likely result in many warnings, so you might want to change it to:这很可能会导致许多警告,因此您可能希望将其更改为:
curl URL | php -r 'error_reporting(E_ERROR); $s = ""; while($l = fgets(STDIN)) {$s .= $l;} $x=new DOMDocument(); $x->loadHTML($s); $x->preserveWhiteSpace = false; $x->formatOutput = true; echo $x->saveXML();'
Of course you can provide the script within your $PATH
to make it more simple当然,您可以在
$PATH
提供脚本以使其更简单
#!/usr/bin/env php
<?php
error_reporting(E_ERROR);
$input = call_user_func(function(){
$lines = [];
while ($line = fgets(STDIN)) {
$lines[] = $line;
}
return implode("\n", $lines);
});
$domDocument = new DomDocument();
$domDocument->preserveWhiteSpace = false;
$domDocument->formatOutput = true;
$domDocument->loadHTML($input);
echo $domDocument->saveXML();
And save that file for example to /usr/local/bin/phphtmltidy
and make it executeable ( sudo chmod +x /usr/local/bin/phphtmltidy
)并将该文件例如保存到
/usr/local/bin/phphtmltidy
并使其可执行( sudo chmod +x /usr/local/bin/phphtmltidy
)
Then you could simply:那么你可以简单地:
curl URL | phphtmltidy
Of course you could also use node as interpreter and work with a library like this one当然,你也可以使用节点作为解释和工作,就像一个图书馆这样一个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.