3

I am using c# Web.Client to download an html string.

A small example of the html been returned is

 <tbody class='resultBody ' id='Tbody2'>
        <tr id='Tr2' class='firstRow'>
            <td class='cbrow tier_Gold' rowspan='4'>
                <input type='checkbox' name='listingId' value='452' id='Checkbox2' />
            </td>
            <td class='resNum' rowspan='4'>
                <div class='node'>
                    B</div>
            </td>
            <td class='datarow busName' id='Td2'>

            </td>
            <td rowspan='2' class='resLinks'>
            </td>
            <td class="hoops" rowspan='2'>
            </td>
        </tr>
        <tr>
            <td class="datarow">
                <dl class="addrBlock">
                    <dd class="bizAddr">
                        123 ABC St</dd>
                    </dl>
            </td>
        </tr>
    </tbody>
    <tbody class='resultBody ' id='Tbody3'>
        <tr id='Tr3' class='firstRow'>
            <td class='cbrow tier_Gold' rowspan='4'>
                <input type='checkbox' name='listingId' value='99' id='Checkbox3' />
            </td>
            <td class='resNum' rowspan='4'>
                <div class='node'>
                    B</div>
            </td>
            <td class='datarow busName' id='Td3'>

            </td>
            <td rowspan='2' class='resLinks'>
            </td>
            <td class="hoops" rowspan='2'>
            </td>
        </tr>
        <tr>
            <td class="datarow">
                <dl class="addrBlock">
                    <dd class="bizAddr">
                        1111 Some St</dd>
                    </dl>
            </td>
        </tr>
    </tbody>

I am interested in 2 elements of the html but I have no idea the best way to get to them. How would be the best way for me to get the value from and get the inner html from the element

Any suggestions would be great!!!

1 Answer 1

3
  • download the HTML Agility Pack (free)
  • create a new HtmlDocument
  • loadhtml
  • use DOM navigation or an xpath query (SelectSingleNode etc) to find the elements
  • access InerHtml of the elements you want

The API is similar to XmlDocument, but it works on html that isn't xhtml.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.