Private Sub Form_Load() Dim html As New HTMLDocument Dim i As Integer ie.Navigate "d:\1.htm" Set html = ie.Document For i = 0 To html.frames.length - 1 GetImagSrc html.frames(i).Document Next End Sub Private Sub GetImagSrc(doc As Object) Dim i As Integer Dim frmhtml As HTMLDocument Set frmhtml = doc Debug.Print frmhtml.location For i = 0 To frmhtml.images.length - 1 Debug.Print frmhtml.images(i).src Next End Sub1.htm内容 <IFRAME SRC="frame.htm" STYLE="z-index:1" > </IFRAME> frame.htm内容 <img border='0' src='1.bmp'> <p> <img border ='0' src = '2.bmp'> '输出结果 file:///D:/frame.htm file:///D:/1.bmp file:///D:/2.bmp
http://www.mvps.org/emorcillo/en/code/vb6/wbframe.shtmlGetting the IWebBrowser2 interface for each HTML frameThis code enumerates the frames of a HTML page loaded in the WebBrowser control to get they IWebBrowser2 interface. Note: This tip is based on the Microsoft KB article 196340 and requieres the OLELIB.TLB type library. EnumFrames Sub EnumFrames(ByVal wb As WebBrowser) Dim pContainer As olelib.IOleContainer Dim pEnumerator As olelib.IEnumUnknown Dim pUnk As olelib.IUnknown Dim pBrowser As SHDocVw.IWebBrowser2 Set pContainer = wb.Object.Document
' Get an enumerator for the frames If pContainer.EnumObjects(OLECONTF_EMBEDDINGS, pEnumerator) = 0 Then
Set pContainer = Nothing
' Enumerate and refresh all the frames Do While pEnumerator.Next(1, pUnk) = 0
On Error Resume Next
' Clear errors Err.Clear
' Get the IWebBrowser2 interface Set pBrowser = pUnk
If Err.Number = 0 Then Debug.Print "Frame: " & pBrowser.LocationURL End If
Loop
Set pEnumerator = Nothing
End If
End Sub
实现三楼的代码可能要在References定义中加入Microsoft HTML Object Library
For Each a In WB1.Document.Frames.框架名.Document.All If a.tagname = "INPUT" Then If a.name = "name" Then a.value = "csdn" End If End If Next 专拿网页数据。 共同学习!QQ:151329155
搜索tmran的帖子,我已经发了好几遍了。懒得找了,不好意思。
用两个循环 for x = 0 to wb1.document.all.length-1 if wb1.document.all(x).tagname="IFRAME"then for y=0 to wb1.document.all(x).document.all.length-1 if wb1.document.all(x).document.all(y).tagname="INPUT" then 添加处理代码 endif next endif next
Dim html As New HTMLDocument
Dim i As Integer
ie.Navigate "d:\1.htm"
Set html = ie.Document
For i = 0 To html.frames.length - 1
GetImagSrc html.frames(i).Document
Next
End Sub
Private Sub GetImagSrc(doc As Object)
Dim i As Integer
Dim frmhtml As HTMLDocument
Set frmhtml = doc
Debug.Print frmhtml.location
For i = 0 To frmhtml.images.length - 1
Debug.Print frmhtml.images(i).src
Next
End Sub1.htm内容
<IFRAME SRC="frame.htm" STYLE="z-index:1" >
</IFRAME>
frame.htm内容
<img border='0' src='1.bmp'>
<p>
<img border ='0' src = '2.bmp'>
'输出结果
file:///D:/frame.htm
file:///D:/1.bmp
file:///D:/2.bmp
Note: This tip is based on the Microsoft KB article 196340 and requieres the OLELIB.TLB type library.
EnumFrames
Sub EnumFrames(ByVal wb As WebBrowser)
Dim pContainer As olelib.IOleContainer
Dim pEnumerator As olelib.IEnumUnknown
Dim pUnk As olelib.IUnknown
Dim pBrowser As SHDocVw.IWebBrowser2 Set pContainer = wb.Object.Document
' Get an enumerator for the frames
If pContainer.EnumObjects(OLECONTF_EMBEDDINGS, pEnumerator) = 0 Then
Set pContainer = Nothing
' Enumerate and refresh all the frames
Do While pEnumerator.Next(1, pUnk) = 0
On Error Resume Next
' Clear errors
Err.Clear
' Get the IWebBrowser2 interface
Set pBrowser = pUnk
If Err.Number = 0 Then
Debug.Print "Frame: " & pBrowser.LocationURL
End If
Loop
Set pEnumerator = Nothing
End If
End Sub
If a.tagname = "INPUT" Then
If a.name = "name" Then
a.value = "csdn"
End If
End If
Next
专拿网页数据。
共同学习!QQ:151329155
for x = 0 to wb1.document.all.length-1
if wb1.document.all(x).tagname="IFRAME"then
for y=0 to wb1.document.all(x).document.all.length-1
if wb1.document.all(x).document.all(y).tagname="INPUT" then
添加处理代码
endif
next
endif
next