+ Reply to Thread
Results 1 to 2 of 2

Thread: Getting the soruce code of a web page

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    36

    Getting the soruce code of a web page

    I'd like to know how to get the source code of a web page.

    Any ideas ?
    Last edited by franky; 11-07-2012 at 10:10 PM.

  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    14
    Steps :
    1- create a HTTP Web Request to the web page. [i.e: connecting to it]
    2- retrieving the response of that request
    3- read the response
    4- display or save it into variable

    Libraries to be used :
    Code:
    using System.Net;
    Code :
    Code:
            static void Main(string[] args)
            {
                HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("http://www.example.com");
                HttpWebResponse response = (HttpWebResponse)webrequest.GetResponse();
    
                StreamReader sr = new StreamReader(response.GetResponseStream());
                string source_code = sr.ReadToEnd();
                sr.Close();
            }
    You might add the following line to view source code :
    Code:
    Console.Write(source_code);

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts