1
我已经使用下面的代码来解析HTML文档&将其存储为CSV文件。C# - 使用HTML敏捷包获取标签内的文本
string actuald=null;
string data1 = File.ReadAllText("E://text.html");
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();
在HTML文档中,我需要<预> < /预之间抽取位于>的内容。 我的文件的内容看起来像
<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>
但在HTML文档我没有在任何HTML标记的指定类?我应该在属性[“”]中给出什么内容?
你需要显示HTML,并指定要提取什么。 – CodingIntrigue
srry但不明白... –
从您向我们展示的内容中,尝试使用'Attributes [“foo”]' –