【发布时间】:2010-03-10 03:54:10
【问题描述】:
我正在尝试解析一个 html 文档 使用我从这个实际站点找到的一些代码 但我不断收到解析错误
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
// There are various options, set as needed
htmlDoc.OptionFixNestedTags = true;
// filePath is a path to a file containing the html
htmlDoc.Load(@"C:\Documents and Settings\Mine\My Documents\Random.html");
// Use: htmlDoc.LoadXML(xmlString); to load from a string
// ParseErrors is an ArrayList containing any errors from the Load statement
if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count > 0)
{
// Handle any parse errors as required
MessageBox.Show("Oh no");
}
else
{
if (htmlDoc.DocumentNode != null)
{
HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//head");
if (bodyNode != null)
{
MessageBox.Show("Hello");
}
}
}
任何帮助将不胜感激:)
【问题讨论】:
-
您没有告诉我们确切的错误信息,也没有提供任何方法让我们重现此信息(即示例 html)。但从理论上讲,这样的事情应该可以工作......
标签: c# html parsing html-agility-pack