是否有一个简单的Bash工具可以快速呈现基本HTML?


38

我不时需要做一个简单的任务,将基本的HTML输出到控制台。我希望将其最小化渲染,以使其一目了然。是否有一个实用程序可以在外壳程序中处理基本的HTML渲染(想想Lynx样式的渲染-但不是实际的浏览器)?

例如,有时我会watch在Apache mod_status页面上放一个:

watch -n 1 curl http://some-server/server-status

该页面的输出是带有一些最小标记的HTML,在shell中显示如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head>
<title>Apache Status</title>
</head><body>
<h1>Apache Server Status for localhost</h1>

<dl><dt>Server Version: Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.15 with Suhosin-Patch</dt>
<dt>Server Built: Jul 22 2014 14:35:25
</dt></dl><hr /><dl>
<dt>Current Time: Wednesday, 19-Nov-2014 15:21:40 UTC</dt>
<dt>Restart Time: Wednesday, 19-Nov-2014 15:13:02 UTC</dt>
<dt>Parent Server Generation: 1</dt>
<dt>Server uptime:  8 minutes 38 seconds</dt>
<dt>Total accesses: 549 - Total Traffic: 2.8 MB</dt>
<dt>CPU Usage: u35.77 s12.76 cu0 cs0 - 9.37% CPU load</dt>
<dt>1.06 requests/sec - 5.6 kB/second - 5.3 kB/request</dt>
<dt>1 requests currently being processed, 9 idle workers</dt>
</dl><pre>__W._______.....................................................
................................................................
................................................................
................................................................
</pre>
<p>Scoreboard Key:<br />
"<b><code>_</code></b>" Waiting for Connection,
"<b><code>S</code></b>" Starting up,
"<b><code>R</code></b>" Reading Request,<br />
"<b><code>W</code></b>" Sending Reply,
"<b><code>K</code></b>" Keepalive (read),
"<b><code>D</code></b>" DNS Lookup,<br />
"<b><code>C</code></b>" Closing connection,
"<b><code>L</code></b>" Logging,
"<b><code>G</code></b>" Gracefully finishing,<br />
"<b><code>I</code></b>" Idle cleanup of worker,
"<b><code>.</code></b>" Open slot with no current process</p>
<p />

在Lynx中查看时,相同的HTML呈现为:Apache状态(第1页,共2页)本地主机的Apache服务器状态

   Server Version: Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.15 with Suhosin-Patch
   Server Built: Jul 22 2014 14:35:25
     ________________________________________________________________________________________________________

   Current Time: Wednesday, 19-Nov-2014 15:23:50 UTC
   Restart Time: Wednesday, 19-Nov-2014 15:13:02 UTC
   Parent Server Generation: 1
   Server uptime: 10 minutes 48 seconds
   Total accesses: 606 - Total Traffic: 3.1 MB
   CPU Usage: u37.48 s13.6 cu0 cs0 - 7.88% CPU load
   .935 requests/sec - 5088 B/second - 5.3 kB/request
   2 requests currently being processed, 9 idle workers

_C_______W_.....................................................
................................................................
................................................................
................................................................

   Scoreboard Key:
   "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
   "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
   "C" Closing connection, "L" Logging, "G" Gracefully finishing,
   "I" Idle cleanup of worker, "." Open slot with no current process

2
bash完全正确,但请查看Xiki,它还能完成更多工作
aarosil 2014年

xiki看起来很棒。
MountainX

Answers:


50

lynx具有“转储”模式,您可以将其用于watch

$ watch lynx https://www.google.com -dump

输出屏幕截图

来自man lynx

   -dump  dumps  the  formatted  output  of  the default document or those
          specified on  the  command  line  to  standard  output.   Unlike
          interactive mode, all documents are processed.  This can be used
          in the following way:

          lynx -dump http://www.subir.com/lynx.html

          Files specified on the command line are  formatted  as  HTML  if
          their  names  end  with one of the standard web suffixes such as
          “.htm or “.html”.  Use the -force_html option to  format  files
          whose names do not follow this convention.

这个Ubuntu提问问题还有更多选择。


2
天猫很棒。当您的连接非常差并且需要检查某个站点的内容时,它也是一个非常有用的工具-没有图像,脚本或CSS可以快速加载页面
jammypeach 2014年


8

至少有两个名为html2text1)(2)的程序可以完成此工作。


的确可以,但是-如果有的话-的输出w3m尤其漂亮。用于表。
Suuuehgi

5

elinks也有-dump模式

elinks -dump https://www.google.com

另请参见linkselinks的基础。相同的命令有效……
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.