views:

114

answers:

3

Hi,

Is it possible to retrieve/get the html source code of a certain website and use it in a ASP.NET web application to display them? (without using the copy-paste, of course)

I want my ASP.NET web application to use them as part of a code sample feature I currently working on.

I'm also considering working it on PHP. Any suggestions?

+1  A: 

You can use the HttpWebRequest class to get the html of a URL, and then do whatever you want with it.

Shawn Steward
Is there a way to retrieve it using PHP?
eibhrum
@eibhrum: `$html = file_get_contents('http://some/url');`, or use cURL
Tom Haigh
+1  A: 

You could use the HttpWebRequest class to get a page from a website. Something like the example on this MSDN page would give you the HTML which you could then display.

Graham Clark
+1  A: 

This is what I've used before, can't recall where I found it to give proper credit. I use the stringbuilder to run regex on later.

C#/ASP.NET (Tested only under 2.0)

        string url = "http://www.somesite.com/page.html";
        WebRequest req = WebRequest.Create(url);
        // Get the stream from the returned web response
        StreamReader stream = new StreamReader(req.GetResponse().GetResponseStream());
        // Get the stream from the returned web response
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        string strLine;
        // Read the stream a line at a time and place each one
        // into the stringbuilder
        while ((strLine = stream.ReadLine()) != null) {
            // Ignore blank lines
            if (strLine.Length > 0)
                sb.Append(strLine);
        }
        // Finished with the stream so close it now
        stream.Close();
        string results = sb.ToString();  //replace 'string results' with 'return' if u are calling it.
JClaspill