ts092
ts092

Reputation: 3

Reading string elements in C#

I have a html code parsed in a string. I want to read table tag in the string and read it separately and then store it to a JSON file. I am not able to identify table tag if I try to export JSON, whole html code goes to JSON. Can I directly interpret StreamReader for this purpose or I need to save parsed HTML to string and then perform the operation I need.

Upvotes: 0

Views: 75

Answers (1)

BhavO
BhavO

Reputation: 2399

Use the HtmlAgilityPack library to parse HTML and extract what you need to save into a separate file.

I.e.

var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(htmltablestring);

foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table[@id='table2']")) { 

 streamWriter.WriteLine(table.OuterHtml);

}

New Project URL: http://html-agility-pack.net

http://www.codeproject.com/Articles/659019/Scraping-HTML-DOM-elements-using-HtmlAgilityPack-H

Upvotes: 2

Related Questions