拿www.baidu.com举例
1.读www.baidu.com取源文件
2判断,源文件里是否有<a href="http://map.baidu.com">地&nbsp;图</a>,这么一段,
3如果有,截取“地&nbsp;图”到list1,
4如果没有<a href="http://map.baidu.com">地&nbsp;图</a>这一段,执行Command3,
这个该怎么写

解决方案 »

  1.   

    Do
    DoEvents
    If WebBrowser1.Busy = True Then
    Else    Dim htmhref As New HTMLAnchorElement
        Dim htmldoc As New HTMLDocument
        Dim htmlEle As New HTMLDTElement
        Dim htmlEles As IHTMLElementCollection
        Dim nlen As Long
        Set htmldoc = WebBrowser1.Document
        Set htmlEles = htmldoc.All
        nlen = htmlEles.length
        Dim i As Long
        Dim j As Long
        j = 0
        For i = 0 To nlen - 1
            Set htmlEle = htmlEles.Item(i)
            If (htmlEle.tagName = "A") Then
                Set htmhref = htmlEle
                aaa = "http://map.baidu.com"
                 If InStr(1, htmhref.href, aaa) <> 0 Then
                    Ret = SendMessageFind(List1.hwnd, LB_FINDSTRING, 0, (htmhref.href))
                    If Ret = LB_ERR Then
                        List1.AddItem htmhref.href
                        If List1.ListCount >= 1000 Then Exit Do
                        Me.Caption = List1.ListCount
                    End If
                End If
            End If
        Next i
    End If
    Loop
      

  2.   

    条件23写错了吧?你意思应该是如果有个链接地址为http://map.baidu.com则取它的链接文字?读取网页源文件的我给你个快速的函数,基本也是通用的:
    '入口参数为url,返回值为网页源代码
    Private Function getHtmlStr$(strUrl$)
        Dim XmlHttp As Object
        Set XmlHttp = CreateObject("Microsoft.XMLHTTP")
        XmlHttp.Open "GET", strUrl, False
        XmlHttp.send
        getHtmlStr = StrConv(XmlHttp.ResponseBody, vbUnicode)
        Set XmlHttp = Nothing
    End Function