How to grab html code from remote website?

  • Thread starter Thread starter Vjay77
  • Start date Start date
V

Vjay77

How to grab html code from remote website?
can someone help?
please let me know...
vjay
 
Here's a function I wrote for what you're asking, if I understand you.
For this to work you need Imports System.Net and Imports System.IO.

Public Function GetSource(ByVal URL As String) As String

Dim vSource As String = ""
Dim HTTPRequest As HttpWebRequest
Dim vURL As Uri
Dim sr As StreamReader
Dim Ln As String
Dim rs As HttpWebResponse
Dim inStr As Stream
Dim line As String
Dim bodyReader As StreamReader

vURL = New Uri(URL)
HTTPRequest = WebRequest.Create(URL)
HTTPRequest.AllowAutoRedirect = True
HTTPRequest.MaximumAutomaticRedirections = 10
HTTPRequest.Method = "GET"
HTTPRequest.ProtocolVersion = New Version(1, 0)
HTTPRequest.Timeout = New TimeSpan(0, 0, 30).TotalMilliseconds
HTTPRequest.UserAgent = "Mozilla/3.0 (compatible; Enigmatic/1.0)"

rs = HTTPRequest.GetResponse()
vURL = rs.ResponseUri
inStr = rs.GetResponseStream()

If Not (inStr) Is Nothing Then
bodyReader = New StreamReader(inStr)
line = bodyReader.ReadLine()
Do While (line) Is Nothing = False
vSource &= line & vbCrLf
line = bodyReader.ReadLine()
Loop
bodyReader.Close()
bodyReader = Nothing
End If

rs.Close()
rs = Nothing
HTTPRequest = Nothing
Return vSource

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top