Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim url As String, i As Integer
For i = 0 To ListView1.Items.Count - 1 '循环获取ListView所有网址
url = Me.ListView1.Items(i).Text
WebBrowser1.Navigate(url)
gethtml() '用源码中查找所需信息
Next
End Sub
ListView 里10条网址,在程序运行的时候,第一条网址还没有打开加载完成,就开始循环到下一条,以至于无法获取到所需信息
请教高手,有没有办法可以使WebBrowser控件完全加载完成后,在开始向后循环
注:如果这条网址一直打不开,程序在大于20秒后在开始循环下一条
先谢谢高手了
------解决方案--------------------------------------------------------
在按钮事件里让webBrowser只加载第一个网址,并将i变量作为窗体类的成员变量
然后在WebBrowse_DocumetCompleted事件里判断当前网址是否加载完成,如果加载完成,则再加载下一个网址
Private i As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (ListView1.Items.Count > 0) Then
Dim url As String = Me.ListView1.Items(0).Text
i = 0
WebBrowser1.Navigate(url)
End If
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
While (WebBrowser1.IsBusy) '加载中...
Application.DoEvents()
System.Threading.Thread.Sleep(10)
End While
i = i + 1
If (ListView1.Items.Count > i) Then
Dim url As String = Me.ListView1.Items(i).Text
WebBrowser1.Navigate(url)
End If
End Sub
------解决方案--------------------------------------------------------
加载下一个网址前,别忘了调用你的
gethtml() '用源码中查找所需信息