因此,我有一個報告工具,吐出HTML文件中的作業調度統計信息,並且我正在使用Perl來使用這些數據。我不知道如何通過HTML表格。獲取值與Perl
我知道如何使用
$.find('<tr>').each(function(){
variable = $(this).find('<td>').text
});
用jQuery做到這一點,但我不知道如何做到這一點同樣的邏輯用Perl。我該怎麼辦?以下是HTML輸出的示例。每個表格行都包含三個相同的統計數據:對象名稱,狀態和返回代碼。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<meta name="GENERATOR" content="UC4 Reporting Tool V8.00A">
<Title></Title>
<style type="text/css">
th,td {
font-family: arial;
font-size: 0.8em;
}
th {
background: rgb(77,148,255);
color: white;
}
td {
border: 1px solid rgb(208,213,217);
}
table {
border: 1px solid grey;
background: white;
}
body {
background: rgb(208,213,217);
}
</style>
</HEAD>
<BODY>
<table>
<tr>
<th>Object name</th>
<th>Status</th>
<th>Return code</th>
</tr>
<tr>
<td>JOBS.UNIX.S_SITEVIEW.WF_M_SITEVIEW_CHK_FACILITIES_REGISTRY</td>
<td>ENDED_OK - ended normally</td>
<td>0</td>
</tr>
<tr>
<td>JOBS.UNIX.ADMIN.INFA_CHK_REP_SERVICE</td>
<td>ENDED_OK - ended normally</td>
<td>0</td>
</tr>
<tr>
<td>JOBS.UNIX.S_SITEVIEW.WF_M_SITEVIEW_CHK_FACILITIES_REGISTRY</td>
<td>ENDED_OK - ended normally</td>
<td>0</td>
</tr>
使用正則表達式的html是所有邪惡的根源。 http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html – CountMurphy
你*可以*使用正則表達式,但是...是一個可怕的,非常糟糕的主意。 – aus
@CountMurphy我愛[那個答案](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags)。這是昇華的藝術。 – stivlo