积极答复者
如何用VB.net直接操作Internet Explorer_Server(IES)窗口里的网页元素

问题
答案
-
引用com
Microsoft internet controls
microsoft html object library
Dim SWs As New SHDocVw.ShellWindows
Dim ie As SHDocVw.InternetExplorer
For Each ie In SWs
Dim doc As mshtml.HTMLDocument
doc = TryCast(ie.Document, mshtml.HTMLDocument)
If Not doc Is Nothing Then
MsgBox(doc.body.innerHTML)
End If
Next
http://feiyun0112.cnblogs.com/- 已标记为答案 feiyun0112Moderator 2009年8月28日 1:27
全部回复
-
引用com
Microsoft internet controls
microsoft html object library
Dim SWs As New SHDocVw.ShellWindows
Dim ie As SHDocVw.InternetExplorer
For Each ie In SWs
Dim doc As mshtml.HTMLDocument
doc = TryCast(ie.Document, mshtml.HTMLDocument)
If Not doc Is Nothing Then
MsgBox(doc.body.innerHTML)
End If
Next
http://feiyun0112.cnblogs.com/- 已标记为答案 feiyun0112Moderator 2009年8月28日 1:27
-
Function IESHTMLDocument(ByVal Hwnd As Integer) As HtmlDocument
Dim SWs As New SHDocVw.ShellWindows
Dim ie As SHDocVw.InternetExplorer
For Each ie In SWs
Dim doc As mshtml.HTMLDocument
doc = TryCast(ie.Document, mshtml.HTMLDocument)
If ie.HWND = Hwnd And doc IsNot Nothing Then
Return doc
End If
Next
Return Nothing
End Function
使用以上代码时出现异常:
无法将类型为“mshtml.HTMLDocumentClass”的 COM 对象强制转换为类类型“System.Windows.Forms.HtmlDocument”。表示 COM 组件的类型实例不能强制转换为不表示 COM 组件的类型;不过,只要基础 COM 组件支持对接口 IID 的 QueryInterface 调用,就能将这些实例强制转换为接口。
如何返回HTMLDocument? -
Function IESHTMLDocument(ByVal Hwnd As Integer) As mshtml.HTMLDocument
只能用com对象
http://feiyun0112.cnblogs.com/ -
Dim ele As mshtml.IHTMLElement
For Each ele In doc.all
Console.WriteLine(ele.id)
Next
http://feiyun0112.cnblogs.com/- 已编辑 feiyun0112Moderator 2009年8月26日 3:05