Imports System.Threading
Public Class Form1
Dim k = 0 ' 算第幾頁=翻頁次數-1
Dim URL As String
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
URL = "https://www.google.com/?hl=zh-tw&gws_rd=ssl#hl=zh-tw&q=林書豪&start=0"
WebBrowser1.Navigate(URL)
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
TextBox1.Text = "瀏覽器下載網頁完成 目前翻頁次數=" + k.ToString
Dim a As HtmlElement = Nothing
For Each a In WebBrowser1.Document.All
If a.OuterText IsNot Nothing Then
If a.OuterText.Trim = "下一頁" Then
TextBox2.Text = a.OuterHtml
URL = a.GetAttribute("href")
If URL <> "" Then
k = k + 1 ' 翻頁次數+1
Application.DoEvents()
Thread.Sleep(2000) '等待2秒後進行下一頁
WebBrowser1.Navigate(URL)
WebBrowser1.Refresh()
End If
End If
End If
Next
End Sub
End Class
(一直try連結會被google認為異常流量囧rz...)
附載點:http://ppt.cc/a3Ic