HTMLHTML敏捷解析错误
<html>
<head>
<title>Sample Page</title>
</head>
<body>
<form action="demo_form.asp" id="form1" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
代码
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(File.ReadAllText(@"C:\sample.html"));
HtmlNode nd = doc.DocumentNode.SelectSingleNode("//form[@id='form1']");
//nd.InnerHtml is "".
//nd.InnerText is "".
问题
nd.ChildNodes //Collection(to get all nodes in form) is always null.
nd.SelectNodes("/input") //returns null.
nd.SelectNodes("./input") //returns null.
"//form[@id='form1']/input" //returns null.
我想是一个以访问形式的标签的childNodes使用id = form1的一个发生。我在Chrome开发者控制台中尝试了相同的xpath,它的工作方式与我想要的完全一样。 HTMlAgility包在从文件或Web阅读HTML时遇到问题。
问题是什么? –
我想要htmlNodecollection中的所有表单标签的子节点。 –