如何用VB读取网页的源文件???要读取的内容和IE中“查看—源文件”所读取的内容一样。。该怎么做???菜鸟一个,还请高手不吝赐教!!!谢谢啦!!!!

解决方案 »

  1.   

    用msxml,我的代码如下,本来是一个asp网页用的,我稍微改了下放vb里面,但是第一次运行能得到哦源代码,其余的都是历史记录.....同时也麻烦帮看看
    Function getHTTPPage(url)
    Dim Http
    Set Http = CreateObject("MSXML2.XMLHTTP")
    Http.Open "GET", url, False
    Http.send
    If Http.ReadyState <> 4 Then
    Exit Function
    End If
    getHTTPPage = BytesToBstr(Http.responseBody, "GB2312")
    Set Http = Nothing
    If Err.Number <> 0 Then Err.Clear
    End FunctionFunction BytesToBstr(body, Cset)
    Dim objstream
    Set objstream = CreateObject("adodb.stream")
    objstream.Type = 1
    objstream.Mode = 3
    objstream.Open
    objstream.Write body
    objstream.Position = 0
    objstream.Type = 2
    objstream.Charset = Cset
    BytesToBstr = objstream.ReadText
    objstream.Close
    Set objstream = Nothing
    End Function
    Private Sub Command1_Click()
    html = getHTTPPage("http://www.chengdu.cc")
    Text1.Text = html
    html = "xxxxx"
    End Sub
      

  2.   

    最后那个是测试html = "xxxxx"的,忘记删了哈哈
      

  3.   

    Private Sub Command1_Click()
               Dim objSelection
               Dim objTxtRange
     
               Set objSelection = WebBrowser1.Document.selection
               If Not (objSelection Is Nothing) Then
                  Set objTxtRange = objSelection.createRange
                  If Not (objTxtRange Is Nothing) Then
                     Debug.Print objTxtRange.htmlText
                     Set objTxtRange = Nothing
                  End If
                  Set objSelection = Nothing
               End If
       End Sub   Private Sub Form_Load()
         WebBrowser1.Navigate "http://www.applevb.com"
       End Sub
      

  4.   

    个人认为 用 WebBrowser 能实现一般的 查看网页源代码Private Sub Command1_Click()
         WebBrowser1.Navigate "view-source:" & WebBrowser1.LocationURL
    End Sub
      

  5.   

    Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Longdim tmp_Get as string
    If URLDownloadToFile(0, "http://www.csdn.net",App.Path & "\.tmp", 0, 0) = 0 Then
        open app.path & "\.tmp" for input as #1
        line input #1,tmp_Get
        Close #1
        msgbox tmp_Get
        kill app.path & "\.tmp"
    end if
      

  6.   

    引用Inet控件,你搜索一下就知道了。
    dim tem As string
    tem=Inet1.Open("http://www.hao123.com")