Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:33:15+00:00 2026-05-25T17:33:15+00:00

I am new to HTML Agility pack and i haven’t figured out how can

  • 0

I am new to HTML Agility pack and i haven’t figured out how can i parse the following block of code:

<p>
    <div class='myclass1'>
        <div id='idXXXX'>content1<br>content2
        </div>  
        <div class="myclass2">
            <table>
                <tr>
                    <td align="left">content3 <b><a href="">content4</a></b></td>
                    <td align="right">content5 <b><a href="">content6</a></b></td>
                </tr>
            </table>
        </div>
    </div>
</p>

where XXXX is a random generated number.

I have all the code to load the HTML document.

What i want from the above code is to get content1 and content2 and in a different query content4.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:33:16+00:00Added an answer on May 25, 2026 at 5:33 pm
    var doc = new HtmlDocument();
    doc.Load("test.htm");
    var res = doc.DocumentNode.SelectSingleNode("//div[@class='myclass1']");
    var firstDiv = res.SelectSingleNode("div");
    var content1 = firstDiv.ChildNodes[0].InnerText.Trim();
    var content2 = firstDiv.ChildNodes[2].InnerText.Trim();
    var content4 = res.SelectSingleNode(".//div[@class='myclass2']")
                      .SelectSingleNode(".//td[@align='left']/b/a")
                      .InnerText
                      .Trim();
    

    UPDATE:

    If you have multiple divs with the given classes and you want to match the content for each of them you could do this:

    var doc = new HtmlDocument();
    doc.Load("test.htm");
    var res = doc.DocumentNode.SelectNodes("//div[@class='myclass1']");
    foreach (var item in res)
    {
        var firstDiv = item.SelectSingleNode("div");
        var content1 = firstDiv.ChildNodes[0].InnerText.Trim();
        var content2 = firstDiv.ChildNodes[2].InnerText.Trim();
        var content4 = item.SelectSingleNode(".//div[@class='myclass2']")
                           .SelectSingleNode(".//td[@align='left']/b/a")
                           .InnerText
                           .Trim();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML that I'm trying to parse using the HTML Agility
I'm using html agility pack to parse several text files that I load. I
how can I change my Html into SafeHtml Html htmlText = new Html(); htmlText.setText(result.getText());
I am new to HTML and Javascript. Please someone can help me with the
i am using the HTML Agility pack to convert <font size=1>This is a test</font>
I am trying to use the HTML Agility pack to scrape some data from
Im using HTML Agility Pack, and Im trying to replace the InnerText of some
I'm using .NET 3.5 (C#) and the HTML Agility Pack to do some web
Hi so i am trying to parse a webpage with HTML Agilty Pack to
im using HTML Agility Pack to fetch URLs from w webpage. The URL is:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.