那位大侠帮把利用WebBrowser实现的功能改为直接操作IE来实现
怎么把下面利用WEBBROWSER实现的功能改为直接打开IE浏览器来实现其自动填写的功能?
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)If WebBrowser1.LocationURL = "http://148.36.20.220:86/" Then WebBrowser1.Document.Forms(0).TextBox1.Value = sh.Cells(i, 1) '用户名 WebBrowser1.Document.Forms(0).TextBox2.Value = sh.Cells(i, 2) '密码 j = (Int(Rnd * 10) + 3) * 1000 Sleep j DoEvents WebBrowser1.Document.Forms(0).Button1.Click '登录 i = i + 1End If If WebBrowser1.LocationURL = "http://148.36.20.220:86/qd.aspx" Then Dim s As Variant s = pDisp.Document.documentElement.outerHTML If InStr(s, "上午请签到") > 0 Then '改为If InStr(s, "ImageButton1")也一样啊 j = (Int(Rnd * 10) + 5) * 1000 Sleep j '想延时一下等图片按钮好正常显示,但好象没用哦 DoEvents On Error Resume Next Set objDoc = WebBrowser1.Document For k = 0 To objDoc.All.Length - 1 If objDoc.All(k).Name = "ImageButton1" Then objDoc.All(k).Click End If End IfEnd If End Sub
Private Sub Timer1_Timer()On Error Resume NextDim sWind As ShellWindowsDim IE As InternetExplorerSet sWind = New ShellWindowsFor Each IE In sWind If IE.Busy = False Then If LCase(Mid(IE.LocationURL, 1, 4)) <> "file" Then '到这里IE就是Browser了 IE.Document.xxxxx'写你自己的代码就可以 End If End IfNextEnd Sub
[解决办法]
dim Wshell,ieSet Wshell=WScript.CreateObject("WScript.Shell")Set ie=WScript.CreateObject("InternetExplorer.Application")ie.visible=trueie.navigate "http://148.36.20.220:86/"While ie.busydoeventsWendie.Document.Forms(0).TextBox1.Value = sh.Cells(i, 1) '用户名ie.Document.Forms(0).TextBox2.Value = sh.Cells(i, 2) '密码j = (Int(Rnd * 10) + 3) * 1000Sleep jDoEventsie.Document.Forms(0).Button1.Click '登录i = i + 1
[解决办法]
这是lyserver老大写的东西,有些小部分做了修改
'* ************************************** *'* 类名称:IEHooker'* 类功能:IE事件监控类'* 作者:lyserver'* 备注:需要引用Microsoft Internet Controls类库'* ************************************** * Option Explicit Dim WithEvents m_shWindows As ShellWindowsDim m_ieEvent() As IEEventDim m_nIeCount As Long '- -----------------------------------' 过程说明:类初始化'- -----------------------------------Private Sub Class_Initialize()On Error Resume NextReleasemem Dim objIE As InternetExplorer If m_nIeCount < 0 Then m_nIeCount = 0 '加入已打开的IE对象到数组中 Set m_shWindows = New ShellWindows For Each objIE In m_shWindows If InStr(UCase(objIE.FullName), "\IEXPLORE.EXE") Then ReDim Preserve m_ieEvent(m_nIeCount) Set m_ieEvent(m_nIeCount) = New IEEvent Set m_ieEvent(m_nIeCount).m_objIE = objIE Set m_ieEvent(m_nIeCount).m_objDoc = objIE.Document m_nIeCount = m_nIeCount + 1 End If NextEnd Sub '- -----------------------------------' 过程说明:类销毁'- -----------------------------------Private Sub Class_Terminate()On Error Resume NextReleasemem Dim i As Long '销毁数组 For i = 0 To m_nIeCount - 1 Set m_ieEvent(i) = Nothing Next Erase m_ieEventEnd Sub '- -----------------------------------' 过程说明:IE窗口打开事件'- -----------------------------------Private Sub m_shWindows_WindowRegistered(ByVal lCookie As Long)On Error Resume Next Releasemem Dim objIE As InternetExplorer If m_nIeCount < 0 Then m_nIeCount = 0 '加入将要打开的IE对象到数组中 Set objIE = m_shWindows(m_shWindows.Count - 1) If InStr(UCase(objIE.FullName), "\IEXPLORE.EXE") = 0 Then Exit Sub ReDim Preserve m_ieEvent(m_nIeCount) Set m_ieEvent(m_nIeCount) = New IEEvent Set m_ieEvent(m_nIeCount).m_objIE = objIE m_nIeCount = m_nIeCount + 1End Sub '- -----------------------------------' 过程说明:IE窗口关闭事件'- -----------------------------------Private Sub m_shWindows_WindowRevoked(ByVal lCookie As Long)On Error Resume Next Releasemem Dim i As Long Dim blnFound As Boolean '从数组中移出将要关闭的IE对象 For i = 0 To m_nIeCount - 1 If m_ieEvent(i).m_objIE Is Nothing Then blnFound = True If blnFound Then If i = m_nIeCount - 1 Then Exit For Set m_ieEvent(i) = m_ieEvent(i + 1) End If Next m_nIeCount = m_nIeCount - 1 If m_nIeCount > 0 Then ReDim Preserve m_ieEvent(m_nIeCount - 1)End Sub
[解决办法]
Sub test()
Dim ie
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
ie.navigate "http://werdfas.comjasd.com"
While ie.busy Or ie.readystate <> 4
Wend
While ie.document.title <> "登 录"
Wend
While ie.busy Or ie.readystate <> 4
Wend
ie.document.logform.u6name.Value = "460"
ie.document.logform.p6wd.Value = "366"
ie.document.logform.submit
'Set ws = CreateObject("Wscript.shell")
'ws.run "C:\Program Files\6.exe"
'set ws=nothing
set ie=nothing
End Sub
call test