using System.Net; //Namespace //in page load ro any event WebClient client = new WebClient (); string htmlCode = client.Downloa...

Read HTML content using c#

4:39 AM Raghunatha 0 Comments

using System.Net; //Namespace

//in page load ro any event

WebClient client = new WebClient();
string htmlCode = client.DownloadString(http://yourwebsite);

//If you need to get content between <body> tag then do this
string strBody = string.Empty;

strBody = BetweenBodyTag(htmlCode, "<body>", "</body>");



//Use below method if you need to get content between tags

public string BetweenBodyTag(string htmlsouce, string starttag, string endtag)

{

// Find the <body> from the souce string

var body = htmlsouce.IndexOf(starttag);

if (body < 0)

    return string.Empty;

body += starttag.Length;

// Find the </body> tag

var endbody = htmlsouce.IndexOf(endtag, body);

if (endbody < 0)

return string.Empty;

// Return content between <body> and </body>

return htmlsouce.Substring(body, endbody - body);

}
 

0 comments:

Powered by Blogger.