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中的所有表單標籤的子節點。 –