Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have used the following code to parse html document & store it as csv file.

C#
string actuald=null;
string data1 = File.ReadAllText("E://text.html");
//Console.WriteLine(data1);
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(data1);
HtmlNodeCollection col = doc.DocumentNode.SelectNodes("//pre");

foreach (HtmlNode node in col)
{
     actuald=node.Attributes[""].Value;
}
File.WriteAllText("E://text.csv",actuald);
Console.WriteLine("Data Converted");
Console.ReadKey();


but in the html doc i have no class specified under any of the html tags? wt content should i give in the attributes[" "]?? plz help

this how my html file looks like
XML
<HTML><HEAD><TITLE>NCEDC_Search_Results</TITLE></HEAD><BODY>Your search parameters are:<ul>
<li>start_time=1973/01/01,00:00:00
<li>end_time=2037/01/01,00:00:00
<li>minimum_magnitude=3.0
<li>maximum_magnitude=10
<li>etype=E
<li>rflag=A,F,H,I
<li>system=selected
<li>format=ncread
</ul>
<PRE>
Date       Time             Lat       Lon  Depth   Mag Magt  Nst Gap  Clo  RMS  SRC   Event ID
----------------------------------------------------------------------------------------------
1973/01/01 06:59:19.23  36.8037 -121.5087   5.65  3.60   Md   28  35    6 0.09 NCSN    1013957
1973/01/01 07:57:39.65  37.0925 -121.5055   9.19  3.10   ML   45  90    5 0.07 NCSN    1013959
</pre></html>
Posted
Updated 11-Jul-13 23:34pm
v3
Comments
StM0n 12-Jul-13 5:28am    
Could you post a simple demo html file?
Member 8657306 12-Jul-13 5:39am    
i have posted what the html file looks like
StM0n 12-Jul-13 6:37am    
What do you want to read exactly?
Andy Lanng 12-Jul-13 5:41am    
What are you trying to achieve here? I do not see what you want to do.
Member 8657306 12-Jul-13 9:09am    
i want to read the contents btwn <pre> </pre> tag

Use Html Agility Pack[^] for parsing (X)HTML files.
 
Share this answer
 
Comments
Member 8657306 16-Jul-13 12:57pm    
i am able to parse the html file & get the content , but how do i convert it into csv file, that can be converted into a database?
Using html agility pack you can easily do this.

C#
foreach (HtmlNode node in col)
{
     actuald=actualid + node.Value;
}
File.WriteAllText("E://text.csv",actuald);
Console.WriteLine("Data Converted");
Console.ReadKey();
 
Share this answer
 
Comments
Member 8657306 16-Jul-13 12:56pm    
this is not working... how can i simply create a csv file??? i dont understand :(
sorry, I have problem I can't find the method called (LoadHtml) could you tell me how can I use it
thanks in advance :)
 
Share this answer
 
Comments
CHill60 20-Aug-15 10:28am    
If you want to respond to a post use the "Have a Question or Comment" link next to it, or the "Reply" link to a comment. Don't post questions as solutions - apart from the fact that very few people will bother to read it you will attract reports and downvotes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900