我用webbrowser打开一个网页,如何让webbrowser随机访问网页里面的连接呢??就比如说我用webbrowser打开百度搜索后出现的那些网页链接,如何随机访问他们???

解决方案 »

  1.   

    dim oCollection,
    oCollection=webbrowser1.document.getElementsByTagName("A")
    这个oCollection就是所有A链接的数组集合,然后搞个集合长度内的随机数字k
    oCollection(k).click;
      

  2.   

            For Each Web In WebBrowser.Document.links
                If InStr(Web.href, "http://") Then
                    If InStr(adStr, Web.href & vbCrLf) = 0 Then
                        ReDim Preserve Arr(a)
                        Arr(a) = Web.href
                        a = a + 1
                        adStr = adStr & Web.href & vbCrLf
                    End If
                End If
            Next Web        y = intRnd(UBound(Arr), 0)
            
            For n = 0 To WebBrowser.Document.All.Length - 1
                If UCase(WebBrowser.Document.All(n).tagName) = "A" Then
                    If WebBrowser.Document.All(n).href = Arr(y) Then
                        WebBrowser.Document.All(n).Click
                        Exit Sub
                    End If
                End If
            Next n
      

  3.   

    Private Function intRnd(ByVal up As Integer, ByVal lo As Integer) As Integer
        Randomize
        intRnd = Int((up - lo + 1) * Rnd + lo)
    End Function
    我来接分的