我正在使用 VS2010 并使用 HTMLAGilityPack1.4.6(来自 Net40 文件夹)。以下是我的 HTML
<html>
<body>
<div id="header">
<h2 id="hd1">
Patient Name
</h2>
</div>
</body>
</html>
我在 C# 中使用以下代码来访问“hd1”。请告诉我正确的方法。
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
try
{
string filePath = "E:\\file1.htm";
htmlDoc.LoadHtml(filePath);
if (htmlDoc.DocumentNode != null)
{
HtmlNodeCollection _hdPatient = htmlDoc.DocumentNode.SelectNodes("//h2[@id=hd1]");
// htmlDoc.DocumentNode.SelectNodes("//h2[@id='hd1']");
//_hdPatient.InnerHtml = "Patient SurName";
}
}
catch (Exception ex)
{
throw ex;
}
尝试了许多排列和组合...我得到空值。
请帮忙。