Get Sourcecode of website

An easy way to get the sourcecode of any website.


Libraries
using System.Net;

Code Snippet
bool TryGetWebisteCode(string url, out string code) {
    try {
        using (WebClient client = new WebClient()) {
            code = client.DownloadString(url);
        }
        return true;
    } catch (Exception) {
        return false;
    }
}


Implementation

Use the function above to get code from a specific url and return the full code using Console.WriteLine: <code> string htmlCode = string.Empty; if (TryGetWebisteCode("https://www.google.com", out htmlCode) Console.WriteLine(htmlCode); </code>





Comments
  • mode_editWrite a comment



  • forumComments




Embed Code

We provide special containers which include the full snippet and a link to this site. So for example when you make a tutorial and you are using code from this site, you can use one of the following snippet embeddings:

Load Preview Get Code Close Preview







    Share
    Rating
    thumb_up 0 thumb_down
    Author
    Thorolus

    I'm the head developer and co-founder of GlovilGames Studios (glovilgames.com) and other platforms GlovilGames created, like vsnippets.com, worth-calculator.net, python-obfuscator.com and some mobile apps and games.

    Tags
    WebClient
    Website



    Informations

    posted on 2016-10-08 23:11:20

    viewed 124 times

    snippet's UUID is 57f960f81906a

    Similar Snippets