三种方法获取指定 URL 的 HTML
一 、
2、
3、
private MSXML2.XMLHTTP http = new MSXML2.XMLHTTP();
string body;
http.open("GET",picurl,false,"","");
http.send("");
body =http.responseText.Replace("\n",null).Replace("\r",null).ToLower();
'获取网页的 HTML
' Dim webclient As New System.Net.WebClient
'Dim webclient As System.Net.HttpWebRequest
Dim strem As Stream
'Dim htmlbyte() As Byte
Dim htmlbody As String = ""
Dim tstr As String = ""
Dim req As System.Net.HttpWebRequest
Dim res As System.Net.HttpWebResponse
Try
req = System.Net.HttpWebRequest.Create(fileName)
res = req.GetResponse()
strem = res.GetResponseStream
Dim strRead As New StreamReader(strem, System.Text.Encoding.UTF8)
htmlbody = strRead.ReadToEnd()
strRead.Close()
strRead = Nothing
'htmlbyte = webclient.DownloadData(fileName)
'htmlbody = System.Text.Encoding.GetEncoding("gb2312").GetString(htmlbyte)
Catch ex As Exception
Return False
End Try
' Dim webclient As New System.Net.WebClient
'Dim webclient As System.Net.HttpWebRequest
Dim strem As Stream
'Dim htmlbyte() As Byte
Dim htmlbody As String = ""
Dim tstr As String = ""
Dim req As System.Net.HttpWebRequest
Dim res As System.Net.HttpWebResponse
Try
req = System.Net.HttpWebRequest.Create(fileName)
res = req.GetResponse()
strem = res.GetResponseStream
Dim strRead As New StreamReader(strem, System.Text.Encoding.UTF8)
htmlbody = strRead.ReadToEnd()
strRead.Close()
strRead = Nothing
'htmlbyte = webclient.DownloadData(fileName)
'htmlbody = System.Text.Encoding.GetEncoding("gb2312").GetString(htmlbyte)
Catch ex As Exception
Return False
End Try
2、
'获取网页的 HTML
Dim webclient As New System.Net.WebClient
Dim htmlbyte() As Byte
Dim htmlbody As String = ""
Dim tstr As String = ""
Try
htmlbyte = webclient.DownloadData(fileName)
htmlbody = System.Text.Encoding.GetEncoding("gb2312").GetString(htmlbyte)
Catch ex As Exception
Return False
End Try
webclient.Dispose()
webclient = Nothing
htmlbyte = Nothing
Dim webclient As New System.Net.WebClient
Dim htmlbyte() As Byte
Dim htmlbody As String = ""
Dim tstr As String = ""
Try
htmlbyte = webclient.DownloadData(fileName)
htmlbody = System.Text.Encoding.GetEncoding("gb2312").GetString(htmlbyte)
Catch ex As Exception
Return False
End Try
webclient.Dispose()
webclient = Nothing
htmlbyte = Nothing
3、
private MSXML2.XMLHTTP http = new MSXML2.XMLHTTP();
string body;
http.open("GET",picurl,false,"","");
http.send("");
body =http.responseText.Replace("\n",null).Replace("\r",null).ToLower();