none
Need only text from the HTML text RRS feed

  • Question

  • Hi,

    I need C# code to get only the text which is there in the HTML Text.

    Below is the HTML Text

    <p><strong><span id="ctl00_ctl50_g_ccf7b312_734e_4c72_9420_c31860bc599b_lblTitle" style="font-size: large;">Five campus trends to watch in 2018<br /></span></strong><span id="ctl00_ctl50_g_ccf7b312_734e_4c72_9420_c31860bc599b_lblTitle" style="font-size: small;">What can we expect to see on higher education campuses this year? Check out what will shape real estate and facilities in 2018.</span></p>

    I need to get the strings which i have marked in bold.

    Regards,

    Sunil

    Tuesday, August 6, 2019 11:58 AM

Answers

  • With HtmlAgilityPack you can load your HTML to a HtmlDocument. This Object has  DocumentNode property which has an InnerText property. This will most likely deliver the requested content.
    • Marked as answer by Sunil A M Wednesday, August 7, 2019 5:14 AM
    Tuesday, August 6, 2019 12:31 PM
  • You can just use the WebBrowser control =>

    private System.Windows.Forms.WebBrowser webBrowser1;

    webBrowser1 = new System.Windows.Forms.WebBrowser();
    webBrowser1.DocumentText = "";
    HtmlDocument htmlDoc1 = webBrowser1.Document;
    htmlDoc1.OpenNew(false);
    htmlDoc1.Write("<p><strong><span id=\"ctl00_ctl50_g_ccf7b312_734e_4c72_9420_c31860bc599b_lblTitle\" style=\"font-size: large;\">Five campus trends to watch in 2018<br /></span></strong><span id=\"ctl00_ctl50_g_ccf7b312_734e_4c72_9420_c31860bc599b_lblTitle\" style=\"font-size: small;\">What can we expect to see on higher education campuses this year? Check out what will shape real estate and facilities in 2018.</span></p>");
    Console.WriteLine(htmlDoc1.Body.InnerText); 

    result =>

    Five campus trends to watch in 2018
    What can we expect to see on higher education campuses this year? Check out what will shape real estate and facilities in 2018.




    • Edited by Castorix31 Tuesday, August 6, 2019 1:52 PM
    • Marked as answer by Sunil A M Wednesday, August 7, 2019 5:14 AM
    Tuesday, August 6, 2019 1:51 PM

All replies

  • With HtmlAgilityPack you can load your HTML to a HtmlDocument. This Object has  DocumentNode property which has an InnerText property. This will most likely deliver the requested content.
    • Marked as answer by Sunil A M Wednesday, August 7, 2019 5:14 AM
    Tuesday, August 6, 2019 12:31 PM
  • Can u send me some sample code please
    Tuesday, August 6, 2019 1:20 PM
  • You can just use the WebBrowser control =>

    private System.Windows.Forms.WebBrowser webBrowser1;

    webBrowser1 = new System.Windows.Forms.WebBrowser();
    webBrowser1.DocumentText = "";
    HtmlDocument htmlDoc1 = webBrowser1.Document;
    htmlDoc1.OpenNew(false);
    htmlDoc1.Write("<p><strong><span id=\"ctl00_ctl50_g_ccf7b312_734e_4c72_9420_c31860bc599b_lblTitle\" style=\"font-size: large;\">Five campus trends to watch in 2018<br /></span></strong><span id=\"ctl00_ctl50_g_ccf7b312_734e_4c72_9420_c31860bc599b_lblTitle\" style=\"font-size: small;\">What can we expect to see on higher education campuses this year? Check out what will shape real estate and facilities in 2018.</span></p>");
    Console.WriteLine(htmlDoc1.Body.InnerText); 

    result =>

    Five campus trends to watch in 2018
    What can we expect to see on higher education campuses this year? Check out what will shape real estate and facilities in 2018.




    • Edited by Castorix31 Tuesday, August 6, 2019 1:52 PM
    • Marked as answer by Sunil A M Wednesday, August 7, 2019 5:14 AM
    Tuesday, August 6, 2019 1:51 PM