使用 bash/Perl 中的正则表达式从 html 表中提取值
我想用 munin 监控我的 oki 打印机,所以我尝试改编这个插件 到我的打印机。
我的打印机 http 服务器中的页表是:
<table width="560" border="0" cellspacing="2" cellpadding="3">
<tr class="sub_item_color">
<td class="normal" width="200" align="right" valign="bottom" rowspan="2">Media Size</td>
<td class="normal" width="90" align="left">Color</td>
<td class="normal" width="90" align="left">Color</td>
<td class="normal" width="90" align="left">Mono</td>
<td class="normal" width="90" align="left">Mono</td>
</tr>
<tr class="sub_item_color">
<td class="normal" width="90" align="left">A3/Tabloid</td>
<td class="normal" width="90" align="left">A4/Letter</td><td class="normal" width="90" align="left">A3/Tabloid</td>
<td class="normal" width="90" align="left">A4/Letter</td>
</tr>
<tr class="sub_item_color">
<td class="normal" width="200" align="left">Total Impressions</td>
<td class="normal" width="90" align="right">21906</td>
<td class="normal" width="90" align="right">33491</td>
<td class="normal" width="90" align="right">2084</td>
<td class="normal" width="90" align="right">4460</td>
</tr>
<tr class="sub_item_color">
<td class="normal" width="200" align="left">Total A4/Letter Impressions</td>
<td class="normal" colspan="2" align="center"><b>Color:77303</B></td>
<td class="normal" colspan="2" align="center"><b>Mono:8628</B></td>
</tr>
</table>
munin 脚本正在执行以下操作:
infopage=`wget -q -O - http://root:$password@$destination/printer/printerinfo_top.htm | perl -p -e 's/\n/ /m'`
echo tray1.value `echo $infopage | perl -p -e 's/^.+Tray\ 1\ Page\ Count\:\ \<\/TD\>\<TD\ WIDTH\=\"94\"\>([0-9]+)\<.+$/$1/'`
我如何获得总印数?
I want to monitor my oki printer with munin, so I am trying to adapt this plugin to my printer.
The table of pages in my printer http server is:
<table width="560" border="0" cellspacing="2" cellpadding="3">
<tr class="sub_item_color">
<td class="normal" width="200" align="right" valign="bottom" rowspan="2">Media Size</td>
<td class="normal" width="90" align="left">Color</td>
<td class="normal" width="90" align="left">Color</td>
<td class="normal" width="90" align="left">Mono</td>
<td class="normal" width="90" align="left">Mono</td>
</tr>
<tr class="sub_item_color">
<td class="normal" width="90" align="left">A3/Tabloid</td>
<td class="normal" width="90" align="left">A4/Letter</td><td class="normal" width="90" align="left">A3/Tabloid</td>
<td class="normal" width="90" align="left">A4/Letter</td>
</tr>
<tr class="sub_item_color">
<td class="normal" width="200" align="left">Total Impressions</td>
<td class="normal" width="90" align="right">21906</td>
<td class="normal" width="90" align="right">33491</td>
<td class="normal" width="90" align="right">2084</td>
<td class="normal" width="90" align="right">4460</td>
</tr>
<tr class="sub_item_color">
<td class="normal" width="200" align="left">Total A4/Letter Impressions</td>
<td class="normal" colspan="2" align="center"><b>Color:77303</B></td>
<td class="normal" colspan="2" align="center"><b>Mono:8628</B></td>
</tr>
</table>
That munin script is doing this:
infopage=`wget -q -O - http://root:$password@$destination/printer/printerinfo_top.htm | perl -p -e 's/\n/ /m'`
echo tray1.value `echo $infopage | perl -p -e 's/^.+Tray\ 1\ Page\ Count\:\ \<\/TD\>\<TD\ WIDTH\=\"94\"\>([0-9]+)\<.+$/$1/'`
How I could get the total impressions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案作为 Unix 过滤器实现,就像问题中一样,由于 XPath,它的可读性和声明性更强。
Solution implemented as a Unix filter like in the question, only much more readable and declarative thanks to XPath.