Get Page Source Code


/ Published in: VB.NET
Save to your folder(s)

You can use this to get the page source code of any valid URL. Tested on VS2010.


Copy this code and paste it in your HTML
  1. Function getPageSource(ByVal url As String) As String
  2.  
  3. Dim sourcecode As String = String.Empty
  4.  
  5. Try
  6.  
  7. Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(url)
  8. Dim response As System.Net.HttpWebResponse = request.GetResponse()
  9.  
  10. Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
  11.  
  12. sourcecode = sr.ReadToEnd()
  13.  
  14. Catch ex As Exception
  15. MsgBox(ex.Message)
  16. End Try
  17.  
  18. Return sourcecode
  19.  
  20. End Function

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.