【发布时间】:2011-09-07 23:08:59
【问题描述】:
想知道是否有人可以在这方面给我一些指导。我花了相当多的时间在上面,但似乎没有得到任何结果:
我有一个隐藏字段,我试图从 VB.Net 中的 HTML 文档中解析出来。我在 WPF 应用程序中使用 System.Windows.Controls.WebBrowser 控件并处理 LoadCompleted 事件。在 LoadCompleted 事件处理程序中,我执行以下操作:
Dim htmlDocument As mshtml.IHTMLDocument2 = Me.WebBrowser.Document
Dim allElements As mshtml.IHTMLElementCollection = htmlDocument.body.all
Dim hiddenField As mshtml.IHTMLInputElement = allElements.tags("hidField")
我试图访问的隐藏字段在我的 .aspx 文件中声明如下:
<asp:HiddenField runat="server" ID="hidField"/>
问题是这个allElements.tags("hidField") 返回null。我对 mshtml 库做错了吗?我对此没有太多经验,并认为我需要做这样的事情来找到我的隐藏字段元素。如果您需要更多信息,请告诉我。提前感谢您的帮助。
编辑
这是我为有兴趣的人提供的最终工作解决方案:
Dim htmlDocument As mshtml.IHTMLDocument2 = Me.WebBrowser.Document
Dim allElements As mshtml.IHTMLElementCollection = htmlDocument.body.all
Dim allInputs As mshtml.IHTMLElementCollection = allElements.tags("input")
For Each element As mshtml.IHTMLInputElement In allInputs
If element.type = "hidden" And element.name.Contains("hidField") Then
MessageBox.Show(element.value)
End If
Next
【问题讨论】: