不定时上论坛解答问题。
定时部分用Timmer就不说了,发送部分
1:用异步下载方式
Dim oADL As AsyncDownload
oADL.Download URL, , , "Post", , "UserName=uname&PWD=password"
2:用WebBrowser控件
'赋值
WebBrowser1.Document.All.UserName.Value = "uname"
WebBrowser1.Document.All.PWD.Value = "password"
'提交
Private Sub cmd点击注册帐号提交_Click()
On Error Resume Next
'对于没有Name的没找到好方法,只能用这种笨方法,你有如好的方法可告诉我:)
Dim i As Integer
Dim j As Integer
For i = 0 To Val(WebBrowser1.Document.All.length - 1)
If WebBrowser1.Document.All.Item(i).Name <> "login" Then
Else
j = i
Exit For
End If
Next
WebBrowser1.Document.All.Item(i).Click
End Sub
Public Event NewWindow(Cancel As Boolean)
Public Event Quit()
Public Event BeforeNavigate(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
Public Event DocumentComplete(ByVal pDisp As Object, URL As Variant)
Public WithEvents IE As InternetExplorer
Dim WithEvents MyTimer As Timer
Dim m_lCookie As Long
Private Sub Class_Terminate()
On Error Resume Next
MyTimer.Enabled = False
Form1.Controls.Remove ("VB.Timer" & CStr(lCookie))
Set IE = Nothing
End Sub
Public Property Let lCookie(ByVal lNewCookie As Long)
m_lCookie = lNewCookie
Set MyTimer = Form1.Controls.Add("VB.Timer", "MyTimer" & CStr(m_lCookie))
MyTimer.Interval = 1000
MyTimer.Enabled = True
End Property
Public Property Get lCookie() As Long
lCookie = m_lCookie
End Property
Public Sub IE_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
RaiseEvent BeforeNavigate(pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel)
MyTimer.Enabled = False
End Sub
Public Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
RaiseEvent DocumentComplete(pDisp, URL)
If IE.Busy = False Then
MyTimer.Enabled = True
End If
End Sub
Public Sub IE_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim m_Cancel As Boolean
RaiseEvent NewWindow(m_Cancel)
cancle = m_Cancel
End Sub
Public Sub IE_OnQuit()
RaiseEvent Quit
End Sub
Private Sub MyTimer_Timer()
Dim i As Integer
Dim Body As Object
Dim MyElement As Object
On Error Resume Next
Set Body = IE.document.Body
Set MyElement = IE.document.getElementById("MyTimeLable")
If TypeName(MyElement) <> "Nothing" Then
MyElement.innerHTML = "<span id=" & Chr(34) & "MyTimeLable" & Chr(34) & ">当前时间:" & Time() & "</span>"
ElseIf TypeName(Body) <> "Nothing" Then
Body.innerHTML = "<span id=" & Chr(34) & "MyTimeLable" & Chr(34) & ">当前时间:" & Time() & "</span></p>" & Body.innerHTML
End If
Err.Clear
End Sub
窗口模块:Form1.frm
Option Explicit
Dim WithEvents Shl As ShellWindows
Dim IEMonitor() As clsIE
Dim IE_Count As Integer
Private Sub Form_Load()
Dim i As Integer
ReDim IEMonitor(0)
Set Shl = New ShellWindows
IE_Count = 0
For i = 0 To Shl.Count - 1
If TypeName(Shl.Item(i)) = "IWebBrowser2" Then
ReDim Preserve IEMonitor(IE_Count)
Set IEMonitor(IE_Count) = New clsIE
Set IEMonitor(IE_Count).IE = Shl.Item(i)
IEMonitor(IE_Count).lCookie = i
IE_Count = IE_Count + 1
End If
Next
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
For i = 0 To IE_Count - 1
Set IEMonitor(i) = Nothing
Next
Set Shl = Nothing
End Sub
Private Sub Shl_WindowRegistered(ByVal lCookie As Long)
If TypeName(Shl.Item(Shl.Count - 1)) = "IWebBrowser2" Then
ReDim Preserve IEMonitor(IE_Count)
Set IEMonitor(IE_Count) = New clsIE
Set IEMonitor(IE_Count).IE = Shl.Item(Shl.Count - 1)
IEMonitor(IE_Count).lCookie = lCookie
IE_Count = IE_Count + 1
End If
End Sub
Private Sub Shl_WindowRevoked(ByVal lCookie As Long)
Dim i As Integer, j As Integer
For i = 0 To IE_Count - 1
If lCookie = IEMonitor(i).lCookie Then
For j = i + 1 To IE_Count - 1
Set IEMonitor(j - 1) = IEMonitor(j)
Next
IE_Count = IE_Count - 1
Set IEMonitor(IE_Count) = Nothing
ReDim Preserve IEMonitor(IE_Count)
End If
Next
End Sub