<html><body>
<form id="form1">
<input name="foo1" value="bar1" />
<!-- Other elements -->
</form>
<form id="form2">
<input name="foo2" value="bar2" />
<!-- Other elements -->
</form>
</body></html>
Test:
HtmlDocument doc = new HtmlDocument();
doc.Load(@"D:\test.html");
foreach (HtmlNode node in doc.GetElementbyId("form2").SelectNodes(".//input"))
{
Console.WriteLine(node.Attributes["value"].Value);
}
Tuyên bố doc.GetElementbyId("form2").SelectNodes(".//input")
mang lại cho tôi một tham chiếu null.
Mọi thứ tôi đã làm sai? cảm ơn.
Điều này có nghĩa là, trừ khi bạn sử dụng 'HtmlNode.ElementsFlags.Remove (" form ");', không thể phân tích cú pháp các phần tử 'form' thông qua HAP? –
@Kevin, tôi không có kiến thức về bất kỳ giải pháp thay thế nào khác. –
5 năm sau - vẫn là một yêu cầu, vẫn là câu trả lời đúng. Ngoài ra, vẫn phải được thay đổi trong chính gói đó ... – getglad