简体   繁体   English

如何在C#中获取孩子的内文

[英]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. 因此,我还是C#的新手,我试图弄清楚如何从webBrowser中获取一些信息。

So the Code in the Html is: 因此,HTML中的代码是:

 <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". 现在,我正试图从“过去”的这些孩子中找出Inntertext。

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. 但是作为新手,我真的不知道如何利用Children元素,现在就被困在这里。

Any Help is welcome, Thanks! 欢迎任何帮助,谢谢! -root -根

Children is actually a collection of multiple HtmlElements. 子级实际上是多个HtmlElements的集合。 You need to iterate over each one in some way to obtain the InnerText. 您需要以某种方式遍历每一个以获得InnerText。

Example: 例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM