Public Class MainClass
Public Shared Sub Main()
System.Console.WriteLine(GetPageHTML("http://www.google.com", 100))
End Sub
Public Shared Function GetPageHTML(ByVal URL As String, Optional ByVal TimeoutSeconds As Integer = 10) As String
Dim objRequest As Net.WebRequest
Dim objResponse As Net.WebResponse
Dim objStreamReceive As System.IO.Stream
Dim objEncoding As System.Text.Encoding
Dim objStreamRead As System.IO.StreamReader
Try
objRequest = Net.WebRequest.Create(URL)
objRequest.Timeout = TimeoutSeconds * 1000
objResponse = objRequest.GetResponse
objStreamReceive = objResponse.GetResponseStream
objEncoding = System.Text.Encoding.GetEncoding("utf-8")
objStreamRead = New System.IO.StreamReader(objStreamReceive, objEncoding)
GetPageHTML = objStreamRead.ReadToEnd()
If Not objResponse Is Nothing Then
objResponse.Close()
End If
Catch
Return ""
End Try
End Function
End Class
|