【发布时间】:2013-07-12 09:22:25
【问题描述】:
我已使用以下代码解析 HTML 文档并将其存储为 CSV 文件。
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 标签下指定类?在attributes[""]中应该给出什么内容?
【问题讨论】:
-
您需要显示 HTML 并指定要提取的内容。
-
srry 但没明白...
-
根据您向我们展示的内容,尝试使用
Attributes["foo"] -
对象引用未设置为对象的实例。我收到此错误
-
奇怪..也许你的
text.html文件和我不一样?
标签: c# html-agility-pack