1

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");

6
  • Maybe 40 is food's firstChild? Commented Feb 29, 2012 at 18:24
  • stackoverflow.com/questions/56107/… This is what I use in my apps. Commented Feb 29, 2012 at 18:25
  • Are you sure this is C#? Looks more like javascript. Commented Feb 29, 2012 at 18:25
  • @Paddy: msdn.microsoft.com/en-us/library/… Commented Feb 29, 2012 at 18:25
  • @SLaks - ah. Well there you go. Didn't know about that. Commented Feb 29, 2012 at 18:29

3 Answers 3

3

You're looking for the InnerHtml property.

Sign up to request clarification or add additional context in comments.

1 Comment

Now, first of all I'm impressed how fast I got a response(thought it'd be a day at least). Second, thank you all for the good answers!
1

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();
}

Comments

0

I believe you are looking for InnerText.

1 Comment

Or InnerHTML will do the trick, here, as SLaks posted just before me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.