Sub Gotoazoogleads() With CreateObject("internetexplorer.application") .navigate "https://apply2.azoogleads.com/" Do Until .Readystate = 4 DoEvents Loop .document.all("dataindex[first_name]").Value = "aaaa" .document.all("dataindex[last_name]").Value = "bbbbb" .document.all("dataindex[email_verify]").Value = "[email protected]" .document.all("dataindex[email]").Value = "[email protected]" .document.all("dataindex[captcha_value]").Value = "NOTKNOW" End With End Sub
https://www.azoogleads.com/corp/apply2.php?i= 比如先打开这个网页,然后再打开程序,获取IE对象,都没问题.主要是如何获取网页里面框架的对象,然后给文本框赋值,虽然能在网页的DocumentComplete获取pDisp,但这不是我想要的,我想实现的是当网页已经打开的时候,通过程序给框架里面的文本框赋值,或者获取框架里面的对象,就向处理不含框架的网页里面一样 普通网页里面可以通过 Set vDob = web.Document(主要是这里,不知道该怎么弄,跨域的框架) For i = 0 To vDob.All.length - 1 Set vTag = vDob.All(i) List1.AddItem vTag.Name Next i
比如你已经取得了IE窗口对象,如变量"IE",然后可以这样做 Dim X As Long, iframeObj As Object, pstr As String For X=1 to IE.window.document.all.length Set iframeObj = IE.window.document.all.item(X) If Not iframeObj is nothing then on error resume next pstr = iframeObj.src if err.number<>0 then err.Clear else if Ucase(pstr) = Ucase("https://apply2.azoogleads.com") then iframeObj.document.body.innerHTML ="框架内容被改了" End If end if End If Next X
Set vDob = web.Document.Frames(0).Document 应该是这样的,但是你的那个网页特殊了点,是https的,这样赋值后并不能访问它的Document,期待高手解决一下
Dim IEEvents As ObjectPrivate Sub Command1_Click() Dim X As Long, Y As Long Dim pstr As String Dim iframeObj As Object Dim IE窗口 As ShellWindows Set IE窗口 = New ShellWindows For Y = 1 To IE窗口.Count On Error Resume Next If UCase(IE窗口.Item(Y).Document.URL) = UCase("https://www.azoogleads.com/corp/apply2.php?i=") Then If Err.Number <> 0 Then Err.Clear If Not IEEvents Is Nothing Then Set IEEvents = Nothing Set IEEvents = IE窗口.Item(Y)
For X = 1 To IEEvents.Document.All.Length Set iframeObj = IEEvents.Document.All.Item(X) If Not iframeObj Is Nothing Then pstr = iframeObj.src If Err.Number <> 0 Then Err.Clear Else If UCase(pstr) = UCase("https://apply2.azoogleads.com") Then iframeObj.Document.body.innerHTML = "框架内容被改了" Exit Sub End If End If End If Next X
End If Next Y Set iframeObj = Nothing Set IE窗口 = Nothing Set IEEvents = Nothing End Sub
Dim IEEvents As ObjectPrivate Sub Command1_Click() Dim X As Long, Y As Long Dim pstr As String Dim vDob, vTag Dim I As Long Dim iframeObj As Object Dim IE窗口 As ShellWindows Set IE窗口 = New ShellWindows For Y = 1 To IE窗口.Count On Error Resume Next If UCase(IE窗口.Item(Y).Document.URL) = UCase("https://www.azoogleads.com/corp/apply2.php?i=") Then If Err.Number <> 0 Then Err.Clear If Not IEEvents Is Nothing Then Set IEEvents = Nothing Set IEEvents = IE窗口.Item(Y) For X = 1 To IEEvents.Document.All.length Set iframeObj = IEEvents.Document.All.Item(X) If Not iframeObj Is Nothing Then pstr = iframeObj.src If Err.Number <> 0 Then Err.Clear Else If UCase(pstr) = UCase("https://apply2.azoogleads.com") Then Debug.Print iframeObj.Document.body.innerHTML '这里获取到的好象并不是IFRAME的对象 Set vDob = iframeObj.Document For I = 0 To vDob.All.length - 1 'On Error Resume Next If LCase(vDob.All(I).tagName) = "input" Then Set vTag = vDob.All(I) List1.AddItem vTag.Name End If Next I Exit Sub End If End If End If Next X
End If Next Y Set iframeObj = Nothing Set IE窗口 = Nothing Set IEEvents = Nothing End Sub
比如这个网页,跨域的.https://www.azoogleads.com/corp/apply2.php?i=
该如何操作呢
With CreateObject("internetexplorer.application")
.navigate "https://apply2.azoogleads.com/"
Do Until .Readystate = 4
DoEvents
Loop
.document.all("dataindex[first_name]").Value = "aaaa"
.document.all("dataindex[last_name]").Value = "bbbbb"
.document.all("dataindex[email_verify]").Value = "[email protected]"
.document.all("dataindex[email]").Value = "[email protected]"
.document.all("dataindex[captcha_value]").Value = "NOTKNOW"
End With
End Sub
需要的是直接在这页里面操作,不是打开那个框架来操作
然后从Frame集合里面找到要得frame不行吗?
不懂楼主什么意思。
比如先打开这个网页,然后再打开程序,获取IE对象,都没问题.主要是如何获取网页里面框架的对象,然后给文本框赋值,虽然能在网页的DocumentComplete获取pDisp,但这不是我想要的,我想实现的是当网页已经打开的时候,通过程序给框架里面的文本框赋值,或者获取框架里面的对象,就向处理不含框架的网页里面一样
普通网页里面可以通过
Set vDob = web.Document(主要是这里,不知道该怎么弄,跨域的框架)
For i = 0 To vDob.All.length - 1
Set vTag = vDob.All(i)
List1.AddItem vTag.Name
Next i
For X=1 to IE.window.document.all.length
Set iframeObj = IE.window.document.all.item(X)
If Not iframeObj is nothing then
on error resume next
pstr = iframeObj.src
if err.number<>0 then
err.Clear
else
if Ucase(pstr) = Ucase("https://apply2.azoogleads.com") then
iframeObj.document.body.innerHTML ="框架内容被改了"
End If
end if
End If
Next X
应该是这样的,但是你的那个网页特殊了点,是https的,这样赋值后并不能访问它的Document,期待高手解决一下
Dim IEEvents As ObjectPrivate Sub Command1_Click()
Dim X As Long, Y As Long
Dim pstr As String
Dim iframeObj As Object
Dim IE窗口 As ShellWindows
Set IE窗口 = New ShellWindows
For Y = 1 To IE窗口.Count
On Error Resume Next
If UCase(IE窗口.Item(Y).Document.URL) = UCase("https://www.azoogleads.com/corp/apply2.php?i=") Then
If Err.Number <> 0 Then Err.Clear
If Not IEEvents Is Nothing Then Set IEEvents = Nothing
Set IEEvents = IE窗口.Item(Y)
For X = 1 To IEEvents.Document.All.Length
Set iframeObj = IEEvents.Document.All.Item(X)
If Not iframeObj Is Nothing Then
pstr = iframeObj.src
If Err.Number <> 0 Then
Err.Clear
Else
If UCase(pstr) = UCase("https://apply2.azoogleads.com") Then
iframeObj.Document.body.innerHTML = "框架内容被改了"
Exit Sub
End If
End If
End If
Next X
End If
Next Y
Set iframeObj = Nothing
Set IE窗口 = Nothing
Set IEEvents = Nothing
End Sub
Dim IEEvents As ObjectPrivate Sub Command1_Click()
Dim X As Long, Y As Long
Dim pstr As String
Dim vDob, vTag
Dim I As Long
Dim iframeObj As Object
Dim IE窗口 As ShellWindows
Set IE窗口 = New ShellWindows
For Y = 1 To IE窗口.Count
On Error Resume Next
If UCase(IE窗口.Item(Y).Document.URL) = UCase("https://www.azoogleads.com/corp/apply2.php?i=") Then
If Err.Number <> 0 Then Err.Clear
If Not IEEvents Is Nothing Then Set IEEvents = Nothing
Set IEEvents = IE窗口.Item(Y)
For X = 1 To IEEvents.Document.All.length
Set iframeObj = IEEvents.Document.All.Item(X)
If Not iframeObj Is Nothing Then
pstr = iframeObj.src
If Err.Number <> 0 Then
Err.Clear
Else
If UCase(pstr) = UCase("https://apply2.azoogleads.com") Then
Debug.Print iframeObj.Document.body.innerHTML '这里获取到的好象并不是IFRAME的对象
Set vDob = iframeObj.Document
For I = 0 To vDob.All.length - 1
'On Error Resume Next
If LCase(vDob.All(I).tagName) = "input" Then
Set vTag = vDob.All(I)
List1.AddItem vTag.Name
End If
Next I
Exit Sub
End If
End If
End If
Next X
End If
Next Y
Set iframeObj = Nothing
Set IE窗口 = Nothing
Set IEEvents = Nothing
End Sub