我用WebBrowser自动点击网页中的链接,发现点击一下CPU占用提高到60%,很耗费资源,请问如果用WebBrowser自动点击网页中的链接,怎么写代码占用CPU少,有什么好方法Option Explicit
Private Sub Command1_Click()
WebBrowser1.Navigate "http://news.baidu.com/" '打开百度新闻网
End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
On Error Resume Next
If WebBrowser1.LocationURL = "http://news.baidu.com/" Then
Dim vDoc, vTag, s
Dim i As Integer
Set vDoc = WebBrowser1.Document
For i = 0 To vDoc.All.Length - 1
If (InStr(Trim(vDoc.All(i).innertext), "财经") <> 0) And UCase("a") = vDoc.All(i).tagname Then '点击百度新闻网中"财经"链接
s = vDoc.All(i)
vDoc.All(i).Click
End If
Next i
End If
End Sub
Private Sub Command1_Click()
WebBrowser1.Navigate "http://news.baidu.com/" '打开百度新闻网
End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
On Error Resume Next
If WebBrowser1.LocationURL = "http://news.baidu.com/" Then
Dim vDoc, vTag, s
Dim i As Integer
Set vDoc = WebBrowser1.Document
For i = 0 To vDoc.All.Length - 1
If (InStr(Trim(vDoc.All(i).innertext), "财经") <> 0) And UCase("a") = vDoc.All(i).tagname Then '点击百度新闻网中"财经"链接
s = vDoc.All(i)
vDoc.All(i).Click
End If
Next i
End If
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
On Error Resume Next
Dim vDoc, vTag, s
Dim i As Integer
if pDisp is WebBrowser1.Object then
Set vDoc = WebBrowser1.Document
For i = 0 To vDoc.All.Length - 1
If (InStr(Trim(vDoc.All(i).innertext), "财经") <> 0) And UCase("a") = vDoc.All(i).tagname Then '点击百度新闻网中"财经"链接
s = vDoc.All(i)
vDoc.All(i).Click
End If
Next i
End If
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
On Error Resume Next
Dim vDoc, vTag, s
Dim i As Integer
if pDisp is WebBrowser1.Object then
Set vDoc = WebBrowser1.Document
For i = 0 To vDoc.All.Length - 1
If (InStr(Trim(vDoc.All(i).innertext), "财经") <> 0) And UCase("a") = vDoc.All(i).tagname Then '点击百度新闻网中"财经"链接
s = vDoc.All(i)
vDoc.All(i).Click
Exit For
End If
Next i
End If
End Sub