Extracting texts from html tags

Total Post:117

Points:821
C#  .NET 
C#
 1204  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. 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().

      Modified On Apr-05-2018 05:56:50 AM

Answer