vb.net如何读取其他人的网页,并且可以自动判断编码的哪种?求函数_百度...
发布网友
发布时间:2024-03-02 09:42
我来回答
共2个回答
热心网友
时间:2024-03-05 03:42
'******************************
'函数名:GetHtml
'作 用:读取其他网站页面内容
'参 数:Url是要读取的网站地址
'返回值:读取后的网站内容
'******************************
Function GetHtml(ByVal Url As String, ByVal bm As String) As String
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(Url)
Dim respHTML As String = ""
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
httpReq.Method = "GET"
Try
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
httpReq.KeepAlive = False ' 获取或设置一个值,该值指示是否与 Internet资源建立持久连接。
Dim reader As StreamReader = New StreamReader(httpResp.GetResponseStream, System.Text.Encoding.GetEncoding(bm))
respHTML = reader.ReadToEnd() 'respHTML就是网页源代码
Catch
respHTML = "zhongduan"
End Try
Return respHTML
End Function
热心网友
时间:2024-03-05 03:37
读网页没问题,至于你说的编码,没搞明白你想问什么。