Anders
Anders

Reputation: 12560

Is there an easy method to read an external web page's source code? ASP.NET

Id like to be able to write a function that reads an external news site and returns the source code of the target page. Any ideas and/or information to get me started?

Upvotes: 1

Views: 714

Answers (3)

Joel Coehoorn
Joel Coehoorn

Reputation: 415620

string GetOtherPage(System.Uri url)
{
    return new System.Net.WebClient().DownloadString(url);
}

Upvotes: 7

Joseph Ferris
Joseph Ferris

Reputation: 12705

If you are talking about the HTML source, then Joel's answer is correct.

However, if you are talking about the actual codebehind for dynamic pages, the answer is "thankfully, no". Most properly configured sites will not return the source code that is dynamically executed to make a page.

Upvotes: 0

smoothdeveloper
smoothdeveloper

Reputation: 2022

You can look at System.Net.WebRequest class and the sample

But please, don't make such crappy code as MSDN sample yourself, use the using idiom where appropriate

Upvotes: 1

Related Questions