Posted By

nimblebits on 04/09/13


Tagged

page code VBNet Website visual Studio source


Versions (?)

Get Page Source Code


 / Published in: VB.NET
 

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

  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  

You need to login to post a comment.