以下为HTML中内容,如何使用linux命令取值‘1’
<div class="container">
<div class='heading'>
<h1>test reporth1>
<p><strong>Start Time:strong> 2022-09-03 19:49:19p>
<p><strong>Duration:strong> 0:00:00.001630p>
<p><strong>Status:strong> <span class="text text-success">Pass <strong>4strong>span> <span class="text text-danger">Failure <strong>1strong>span>p>
<p class='description'>case executionp>
div>
可以使用xmlstarlet来从bash中解析此HTML 。部分系统需要先安装才能使用。
但是此HTML不完整,第3行的后面应当还有一个</div>
,加上去之后才能解析。
xmlstarlet select --template --value-of "/div/p/span[@class='text text-danger']/strong" --nl demo.xml
输出:
1