moutonc
moutonc

Reputation: 239

Parsing HTML tags to find a specific Table Row

Hello everyone I was set up with a Challenge where I must parse through an HTML page to find the end date of all the classes. I am using the HTMLAgilityPack but, this is the first time I have used it, also the webpage who ever set it up has no classes or Id's and the end dates are stored in a Tr H4 tag. I am not sure how to Parse through any hits?

My Code:

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(txtURL.Text);

sw.WriteLine("GET /academics/academic-calendar/ HTTP/1.1");
sw.WriteLine();
String response = sr.ReadToEnd();

txtHTML.Text = response;

Upvotes: 0

Views: 847

Answers (2)

Gabe
Gabe

Reputation: 50493

Using XPath will allow you to get what you need. Here is an example of how to get all the table rows from the declared html.

HtmlDocument htmlDocument = Markup.Parser();                                  
htmlDocument.LoadHtml(html);
htmlDocument.DocumentNode.SelectNodes("/tr");

Upvotes: 1

Oded
Oded

Reputation: 499092

The HtmlDocument object can be queried - you can use XPath to find all elements that follow a specific path or other constraint, you can also use LINQ to query.

I suggest downloading the source package - it comes with many projects with examples of usage.

Upvotes: 1

Related Questions