位置:首页 > 程序设计 > vb2010获取网页源码的函数

vb2010获取网页源码的函数

时间:2014-07-24  |  作者:本站整理  |  阅读:829

vb2010获取网页源码的函数如下:

 Function posthtml(ByVal _URL As String) As String
        Dim TitelStart, TitelEnd As Short
        Dim TitelTxt As String
        Dim url As String = _URL ' 网页地址
        Dim httpReq As System.Net.HttpWebRequest
        Dim httpResp As System.Net.HttpWebResponse
        Dim httpURL As New System.Uri(url)
        httpReq = CType(Net.HttpWebRequest.Create(httpURL), Net.HttpWebRequest)
        httpReq.Method = "GET"
        httpResp = CType(httpReq.GetResponse(), Net.HttpWebResponse)
        Dim reader As IO.StreamReader = New IO.StreamReader(httpResp.GetResponseStream)
        Dim respHTML As String = reader.ReadToEnd() 'respHTML就是网页源代码
        TitelStart = respHTML.IndexOf("<title>") + 7
        TitelEnd = respHTML.IndexOf("</title>")
        TitelTxt = respHTML.Substring(TitelStart, TitelEnd - TitelStart)
        Return TitelTxt.Trim
    End Function

福利游戏

相关文章

更多

精选合集

更多

大家都在玩

热门话题

大家都在看

更多