帮小弟我看下这个代码那里错了
帮我看下这个代码那里错了?
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Set a = WebBrowser1.Document.getElementById("bdeTextArea")
a.onfocus: a.innerText = "测试一下"
Set a = WebBrowser1.Document.getElementById("captcha_container")
While a.Style.display = "none": Sleep 160: DoEvents: Wend
Set a = WebBrowser1.Document.getElementById("captcha")
If Not a Is Nothing Then a.onblur: a.onfocus
Set a = WebBrowser1.Document.getElementById("captcha_content")
While a.Style.display = "none": Sleep 160: DoEvents: Wend
''''主要帮我找下下面这个复制验证码图片的为什么第一次不复制,以后第N次复制的是第N-1张验证图 ;-(
For Each x In WebBrowser1.Document.getElementsByTagName("IMG")
If InStr(1, x.src, "http://tieba.baidu.com/cgi-bin/genimg?", 1) <> 0 Then
Clipboard.Clear
Set CtrlRange = WebBrowser1.Document.body.createControlRange()
CtrlRange.Add (x)
CtrlRange.execCommand ("Copy")
Picture1.Picture = Clipboard.GetData
Exit For
End If
Next
End Sub
Private Sub Form_Activate()
WebBrowser1.Navigate "http://tieba.baidu.com/f?kz=758461931"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
WebBrowser1.Document.parentwindow.scrollby 0, 1610
End Sub
'自己添加1个web,1个command,1个picture就行了
'为什么第一个验证码没法复制??
-------------------------------------->上面可能是验证码图片读取有延迟,可下面还是不行,为啥?
我现在把程序改成这样,为什么还是有问题??
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Set Picture1.Picture = Nothing
Set A = WebBrowser1.Document.getElementById("bdeTextArea")
A.onfocus: A.innerText = "测试一下"
Set A = WebBrowser1.Document.getElementById("captcha_container")
While A.Style.display = "none": Sleep 160: DoEvents: Wend
Set A = WebBrowser1.Document.getElementById("captcha")
If Not A Is Nothing Then A.onblur: A.onfocus
Set A = WebBrowser1.Document.getElementById("captcha_content")
While A.Style.display = "none": Sleep 160: DoEvents: Wend
''''主要帮我找下下面这个复制验证码图片的为什么第一次不复制,以后第N次复制的是第N-1张验证图 ;-(
A:
For Each x In WebBrowser1.Document.getElementsByTagName("IMG")
If InStr(1, x.src, "http://tieba.baidu.com/cgi-bin/genimg?", 1) <> 0 Then
Clipboard.Clear
Set CtrlRange = WebBrowser1.Document.body.createControlRange()
CtrlRange.Add (x)
CtrlRange.execCommand ("Copy")
Picture1.Picture = Clipboard.GetData
Exit For
End If
Next
If Picture1.Picture = False Then GoTo A
End Sub
Private Sub Form_Activate()
WebBrowser1.Navigate "http://tieba.baidu.com/f?kz=758461931"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
WebBrowser1.Document.parentwindow.scrollby 0, 1610
End Sub
第2个验证码显示不对,从第2个就出错,这是为什么??
------解决方案--------------------
可能是我这边网速比较好的缘故 加了延时之后一切都正常了 如果实在不行的 你可以考虑下延时大点
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Set a = WebBrowser1.Document.getElementById("bdeTextArea")
a.onfocus: a.innerText = "测试一下"
Set a = WebBrowser1.Document.getElementById("captcha_container")
While a.Style.display = "none": Sleep 160: DoEvents: Wend
Set a = WebBrowser1.Document.getElementById("captcha")
If Not a Is Nothing Then a.onblur: a.onfocus
Set a = WebBrowser1.Document.getElementById("captcha_content")
While a.Style.display = "none": Sleep 160: DoEvents: Wend
''''主要帮我找下下面这个复制验证码图片的为什么第一次不复制,以后第N次复制的是第N-1张验证图 ;-(
For Each x In WebBrowser1.Document.getElementsByTagName("IMG")
If InStr(1, x.src, "http://tieba.baidu.com/cgi-bin/genimg?", 1) <> 0 Then
Clipboard.Clear
Set CtrlRange = WebBrowser1.Document.body.createControlRange()
CtrlRange.Add (x)
CtrlRange.execCommand ("Copy")
Picture1.Picture = Clipboard.GetData
Exit For
End If
Next
End Sub
Private Sub Form_Activate()
WebBrowser1.Navigate "http://tieba.baidu.com/f?kz=758461931"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
WebBrowser1.Document.parentwindow.scrollby 0, 1610
End Sub
'自己添加1个web,1个command,1个picture就行了
'为什么第一个验证码没法复制??
-------------------------------------->上面可能是验证码图片读取有延迟,可下面还是不行,为啥?
我现在把程序改成这样,为什么还是有问题??
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Set Picture1.Picture = Nothing
Set A = WebBrowser1.Document.getElementById("bdeTextArea")
A.onfocus: A.innerText = "测试一下"
Set A = WebBrowser1.Document.getElementById("captcha_container")
While A.Style.display = "none": Sleep 160: DoEvents: Wend
Set A = WebBrowser1.Document.getElementById("captcha")
If Not A Is Nothing Then A.onblur: A.onfocus
Set A = WebBrowser1.Document.getElementById("captcha_content")
While A.Style.display = "none": Sleep 160: DoEvents: Wend
''''主要帮我找下下面这个复制验证码图片的为什么第一次不复制,以后第N次复制的是第N-1张验证图 ;-(
A:
For Each x In WebBrowser1.Document.getElementsByTagName("IMG")
If InStr(1, x.src, "http://tieba.baidu.com/cgi-bin/genimg?", 1) <> 0 Then
Clipboard.Clear
Set CtrlRange = WebBrowser1.Document.body.createControlRange()
CtrlRange.Add (x)
CtrlRange.execCommand ("Copy")
Picture1.Picture = Clipboard.GetData
Exit For
End If
Next
If Picture1.Picture = False Then GoTo A
End Sub
Private Sub Form_Activate()
WebBrowser1.Navigate "http://tieba.baidu.com/f?kz=758461931"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
WebBrowser1.Document.parentwindow.scrollby 0, 1610
End Sub
第2个验证码显示不对,从第2个就出错,这是为什么??
------解决方案--------------------
可能是我这边网速比较好的缘故 加了延时之后一切都正常了 如果实在不行的 你可以考虑下延时大点