cranzy
cranzy

Reputation: 13

C# Reading data in html tags

How do I read data in-between html tag such as <strong>. For example.

<strong id="food">40</strong>

How do I retrieve the integer 40 from there ? I tried

myBrowser.Document.GetElementById("food").GetAttribute("value");

Upvotes: 1

Views: 2914

Answers (3)

Onur
Onur

Reputation: 599

InnerText

[STAThread]
static void Main(string[] args)
{
    WebBrowser w = new WebBrowser();
    w.Navigate(String.Empty);
    HtmlDocument doc = w.Document;
    doc.Write("<html><head></head><body><p id=\"food\">40</p></body></html>");
    Console.WriteLine(doc.GetElementById("food").InnerText);
    Console.ReadKey();
}

Upvotes: 1

Mike Guthrie
Mike Guthrie

Reputation: 4059

I believe you are looking for InnerText.

Upvotes: 0

SLaks
SLaks

Reputation: 888185

You're looking for the InnerHtml property.

Upvotes: 3

Related Questions