userlip
userlip

Reputation: 77

How to get the Innertext of the childs in C#

So I am still kinda new to C# and I am trying to figure out how to get some information out of my webBrowser.

So the Code in the Html is:

<div id="past">
<div data-rollid="100" class="card card-9">9</div>
<div data-rollid="101" class="card card-11">11</div>
<div data-rollid="102" class="card card-2">2</div>
</div>

and now I am trying to get out the Inntertext from these children from "past".

Right now I only have this here:

private void lastcard()
{
webBrowser1.Document.GetElementById("past").Children;
}

But as newbie I really dont know how to utilizie the Children element and am stuck here right now.

Any Help is welcome, Thanks! -root

Upvotes: 0

Views: 1871

Answers (1)

Arman Peiravi
Arman Peiravi

Reputation: 1098

Children is actually a collection of multiple HtmlElements. You need to iterate over each one in some way to obtain the InnerText.

Example:

HtmlElementCollection elementColl = webBrowser1.Document.GetElementById("past").Children;
foreach (HtmlElement element in elementColl)
{
  string innerText = element.InnerText;
}

Upvotes: 1

Related Questions