|
'首先在工程中加入对
'"Microsoft Internet Controls" (Shdocvw.dll) 和 "Microsoft HTML Object Library" (Mshtml.dll)的引用
'指定浏览器对象的Document
Public mDocument As Object
'参数为网页标题
Public Sub mComGetIEWindows(ByVal IETitle As String)
'浏览器对象集合(包含IE也包含资源管理器)
Dim SWs As New SHDocVw.ShellWindows
Dim IE As SHDocVw.InternetExplorer
Dim Doc
'循环变量
For Each IE In SWs
Doc = IE.Document
If TypeOf Doc Is mshtml.HTMLDocument Then
'if this is an HTML page, display the title
'may or may not be the same as LocationName
If Doc.title = IETitle Then
mDocument = Doc
Exit Sub
End If
End If
Next
End Sub
'首先请打开以下地址:
'http://bbs.163.com
'观看页面,有一个输入框里面有字符,我们的目的就是获取其内容
'查看网页源文件,注意以下这行,其中name="so_title"是我们引用该文本框要用的
'<input name="so_title" type="text" value="输入文章标题" size=" " class="s2">
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'获取标题为网易论坛的IE对象
mComGetIEWindows("网易论坛")
'如果存在该窗口,那么显示其中name属性为so_title的页面对象的内容
If mDocument Is Nothing Then
MsgBox("unkonwn")
Else
MsgBox(mDocument.body.All("so_title").Value)
End If
End Sub |
|