如何使用Nokogiri在<!--Sanction 3-->
中查找文字(解析HTML)?
我在网站中输入搜索字词,结果显示在下一页上。如果符合某些条件,我需要以编程方式从结果页面中获取数据。
我在分析结果页面时注意到,这些项目被分解为制裁。我需要知道制裁是否有数据,如果是,它是否包含我的关键字;我在找县/州。我不知道如何看待制裁。这里有一点HTML:
<!--Sanction 3-->
<table border="2" cellpadding="2" cellspacing="0" width="100%">
<thead>
<tr>
<th class="XXheaderClass" colspan="5" scope="colgroup">
<table bgcolor="#ff9999" width="100%">
<tbody>
<tr>
<td class="XXsanctionHeader1">
<span class="XXtextBold">Requirements Met</span>
</td>
<td class="XXsanctionHeader2">
<span class="XXtextBold">Status: GOOD</span>
</td>
</tr>
</tbody>
</table>
</th>
</tr>
<tr>
<th class="XXheaderClass" width="31%" scope="col">
<span class="XXsmallTextBold">Description</span>
</th>
<th class="XXheaderClass" width="12%" scope="col">
<span class="XXsmallTextBold">Effective Date</span>
</th>
<th class="XXheaderClass" width="12%" scope="col">
<span class="XXsmallTextBold">Number</span>
</th>
<th class="XXheaderClass" width="12%" scope="col">
<span class="XXsmallTextBold">County/State</span>
</th>
<th class="XXheaderClass" width="33%" scope="col">
<span class="XXsmallTextBold">Address and Phone Number</span>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td class="footerClass" colspan="5">
<table class="panelBox">
<tr>
<td>
<a href="SanctionHelpPages/Sanction03Help.aspx" id="MainContent_lvSanction3_sanction03Link" class="outputLinkEx"><span class="XXlinkBold">
Click Here</span></a>
</td>
<td>
<span class="XXtextBold">to resolve,
requirements met.</span>
</td>
</tr>
</table>
</td>
</tr>
</tfoot>
<tbody>
<tr id="MainContent_lvSanction3_Tr1_0">
<td class="XXsmallText">
<span id="MainContent_lvSanction3_lblDescription_0">DESCRIPTION </span>
</td>
<td class="XXsmallText">
<span id="MainContent_lvSanction3_lblEffectiveDate_0">9/19/20011</span>
</td>
<td class="XXsmallText">
<span id="MainContent_lvSanction3_lblNumber_0">1111 </span>
</td>
<td class="XXsmallText">
<span id="MainContent_lvSanction3_lblCountyState_0">MyCounty </span>
</td>
<td class="XXsmallText">
<span id="MainContent_lvSanction3_lblAddressAndPhoneNumber_0">1234 MyRoad AVE. CITY (xxx)xxx-xxxx</span>
</td>
</tr>
</tbody>
</table>
<br />
答案 0 :(得分:6)
您可以使用doc.xpath("//comment()")
查找所有评论节点。然后,您可以遍历这些节点并检查其兄弟节点以获取数据。但是,如果没有更多信息,那么给出一个全面的答案有点困难。