很难,因为webbrowser只是处理、显示服务器返回的页面数据,如果你想知道一个页面是否存在,应该利用INet控件连接,如果返回404,说明页面不存在。

解决方案 »

  1.   

    就是microsoft internet transfer control 控件。msinet.ocx
      

  2.   

    可以!在它的俩个事件里写,看看我的例子:
    Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
    On Error GoTo eee
    If InStr(Text, "完成") <> 0 And WebBrowser1.Visible = True Then
    If WebBrowser1.Visible = False Then WebBrowser1.Visible = True
    If InStr(Text, "shdoclc.dll") <> 0 And Web1.Visible = True Then
     WebBrowser1.Stop
     msgbox“网页未找到!”
     Exit Sub
    End If
    End Ifeee:
    End Sub
    Private Sub WebBrowser1_TitleChange(ByVal Text As String)
    If WebBrowser1.Visible = False Then WebBrowser1.Visible = True
    If (InStr(Text, "找不到") <> 0 Or InStr(Text, "无法") <> 0 Or InStr(Text, "错误") <> 0 Or InStr(Text, "Socket") <> 0 Or InStr(Text, "取消") <> 0 Or InStr(Text, "没有") <> 0) And WebBrowser1.Visible = True Then
     WebBrowser1.Visible = False
     errorlog = writeerrorlog("", "WEB页面" & g_webstr & "未找到!")
     Exit Sub
    ElseIf WebBrowser1.LocationName = "hello world" Then 
    //”hello world“ 为网页的标题
     WebBrowser1.Visible = True
    End IfEnd Sub
      

  3.   

    to: platinumkill(bb) (  ) 信誉:100 
    真的可以吗?你试一下浏览微软的站点,看看你的代码是否有效。Private Sub Command1_Click()
        WebBrowser1.Navigate "http://www.microsoft.com/killbillgates.html"
    End SubPrivate Sub WebBrowser1_StatusTextChange(ByVal Text As String)
    On Error GoTo eee
    If InStr(Text, "完成") <> 0 And WebBrowser1.Visible = True Then
    If WebBrowser1.Visible = False Then WebBrowser1.Visible = True
    If InStr(Text, "shdoclc.dll") <> 0 And Web1.Visible = True Then
     WebBrowser1.Stop
     MsgBox "网页未找到!"
     Exit Sub
    End If
    End Ifeee:
    End Sub
    Private Sub WebBrowser1_TitleChange(ByVal Text As String)
    If WebBrowser1.Visible = False Then WebBrowser1.Visible = True
    If (InStr(Text, "找不到") <> 0 Or InStr(Text, "无法") <> 0 Or InStr(Text, "错误") <> 0 Or InStr(Text, "Socket") <> 0 Or InStr(Text, "取消") <> 0 Or InStr(Text, "没有") <> 0) And WebBrowser1.Visible = True Then
     WebBrowser1.Visible = False
     'errorlog = writeerrorlog("", "WEB页面" & g_webstr & "未找到!")
     Exit Sub
    ElseIf WebBrowser1.LocationName = "hello world" Then
    '//”hello world“ 为网页的标题
     WebBrowser1.Visible = True
    End IfEnd Sub
      

  4.   

    你的程序只是在站点没有默认的404错误处理页面时才有效,现在很多大站点都有自己的错误处理页面,你的提取页面和标题字符的方法很可能不奏效。正确的方法只是用inet控件向站点发出请求,然后从站点返回值中判断。
      

  5.   

    to TechnoFantasy(www.applevb.com) 
    如果网站自己做了404Error页面,服务器端会自己redirect到该页面。
    Response.Redirect以及jsp/asp.net等等语言中的redirect这样的方法,将让WebServer在http header中返回一个remove to ...的header。
    虽然对于WebBrowser的显示来说页面的确还是有的,但是已经是另外一个页面(错误处理页面),没错。可是由于有这个Header的存在,你还是可以捕捉到的:
    Private Sub WebBrowser1_NavigateError(ByVal pDisp As Object, URL As Variant, Frame As Variant, StatusCode As Variant, Cancel As Boolean)
    如果 StatusCode = 404 说明找不到,403拒绝访问 ....
      

  6.   

    是的,我知道webbrowser对象有NavigateError事件,MSDN中有,但是我的VB中的webbrower控件没有暴露这个事件,我不知道是怎么回事。
      

  7.   

    to : joyplay(想吃老虎的小猪) (  ) 
    你在吗?WebBrowser1_NavigateError事件怎么在我的webbrowser控件中没有