EXTRACTING TEXTS FROM HTML TAGS

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
.NET  C# 
C#
 940  View(s)
Ratings:
Rate this:

I have a page like this which has 3 values in li tags

<li>Samsung</li>

<li>Nokia</li>

<li>Sony</li>

 

public string mobilename1 = "";

public string mobilename2 = "";

public string mobilename3 = "";

 

 

    // Use this for initialization

    void Start () {

 

        HtmlWeb htmlweb = new HtmlWeb();

        HtmlAgilityPack.HtmlDocument doc = htmlweb.Load(openUrl);

 

    foreach (HtmlNode nd in doc.DocumentNode.SelectNodes("//li"))

        {

            mobilenames=nd.InnerText.ToString();

 

        }

 

How can I store all 3 values in those strings?

  1. Anchal Kesharwani

    Post:10

    Points:70
    Re: Extracting texts from html tags

    hi jayprakash,


    We will easier to find 3 values in string array, for example:

    List<string> mobilenames = new List<string>();

     

    foreach (HtmlNode nd in doc.DocumentNode.SelectNodes("//li"))

    {

        mobilenames.Add(nd.InnerText.Trim());

     

    InnerText is already a sting so no need to ToString() but get correct mobile names trim the spaces as Trim().

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!