locked
Get the source of a web page RRS feed

  • Question

  • Hello,

    My program needs to get the source of a webpage (eg codeproject.com) and return it into a variable:

    dim sourcecode as string=getsource("http://codeproject.com")


    Thanks in advance
    Sunday, October 15, 2006 1:32 PM

Answers

  • Hi,

    You can do that by using a HttpWebRequest class.

    Dim HttpWReq As HttpWebRequest = _
       CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest)
          
    Dim HttpWResp As HttpWebResponse = _
       CType(HttpWReq.GetResponse(), HttpWebResponse)
    ' Insert code that uses the response object.

    and then you can use the GetResponse stream to retrieve the source.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnethttpwebresponseclassgetresponsestreamtopic.asp

     

    cheers,

    Paul June A. Domag

    Sunday, October 15, 2006 6:05 PM
  • The following will work although it writes to a disk file in between.

     

    My.Computer.Network.DownloadFile("http://codeproject.com", "C:\test.html")
    Dim s As String = My.Computer.FileSystem.ReadAllText("C:\test.html")

    Wednesday, October 18, 2006 5:20 AM

All replies

  • Hi,

    You can do that by using a HttpWebRequest class.

    Dim HttpWReq As HttpWebRequest = _
       CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest)
          
    Dim HttpWResp As HttpWebResponse = _
       CType(HttpWReq.GetResponse(), HttpWebResponse)
    ' Insert code that uses the response object.

    and then you can use the GetResponse stream to retrieve the source.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnethttpwebresponseclassgetresponsestreamtopic.asp

     

    cheers,

    Paul June A. Domag

    Sunday, October 15, 2006 6:05 PM
  • The following will work although it writes to a disk file in between.

     

    My.Computer.Network.DownloadFile("http://codeproject.com", "C:\test.html")
    Dim s As String = My.Computer.FileSystem.ReadAllText("C:\test.html")

    Wednesday, October 18, 2006 5:20 AM