Home > DeveloperSection > Forums > Extracting texts from html tags
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    September-20-2014 2:41 AM

 C# .NET  C# 
Ratings:


 1 Reply(s)
 684  View(s)
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?



Anchal Kesharwani
Anchal Kesharwani

Total Post:10

Points:70
Posted on    September-20-2014 2:58 AM

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().


Don't want to miss updates? Please click the below button!

Follow MindStick