Find text based on HTML comment

How to use Nokogiri to search for text in <!--Sanction 3-->

(HTML parsing)?

I enter a search term on the site and the results are displayed on the next page. I need to grab data programmatically from a results page if it meets certain criteria.

When I analyzed the results page, I noticed that the items were broken down by sanctions. I need to know if the sanction has data and, if so, if it contains my keyword; I am looking for a county / state. I'm not sure how to get him to look at sanction. Here's some 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 />

      

+3


source to share


1 answer


You can use doc.xpath("//comment()")

to find all comment nodes. Then you can iterate over these nodes and check your siblings for your data. It is somewhat difficult to give an exhaustive answer without additional information.



+6


source