简体   繁体   English

Simple HTML Dom:选择和计数子元素(.eq 函数到 Simple HTML Dom)

[英]Simple HTML Dom: Select and count child element (.eq function to Simple HTML Dom)

I can't seem to translate the DOM language to the Simple HTML DOM language.我似乎无法将 DOM 语言翻译成 Simple HTML DOM 语言。 This is the correct solution which is on the Google Chrome console:这是 Google Chrome 控制台上的正确解决方案:

$('div.row.player-sidebar-item', 0).children().eq(17).children().length;
//console answer: 4

and hereby the correct answer, but I need it to be done with Simple HTML DOM and can't find any information for it.并在此给出正确答案,但我需要使用简单的 HTML DOM 来完成,但找不到任何相关信息。 This code is also returning the information I need:此代码还返回我需要的信息:

$('div.col-xs-5.player-sidebar-value', 0).eq(4).children().length;
//console answer: 4

I don't know how I can do this in Simple HTML DOM and thus my code until now:我不知道如何在 Simple HTML DOM 中执行此操作,因此我的代码直到现在:

$countwf = count($futhead->find('div.row.player-sidebar-item', 0)->childNodes(17));

and that is the best I can get there, I don't know how to do this better.这是我能做到的最好的,我不知道如何做得更好。 I hope someone can help me.我希望有一个人可以帮助我。

================ FIRST UPDATE ================ ================ 第一次更新 ================

After the first comment, I have tried this:在第一条评论之后,我试过这个:

echo $countwf = count($futhead->find('div[class=col-xs-5 player-sidebar-value]', 0)->childNodes(4)->children());

this is not working,这不起作用,

echo $countwf = count($futhead->find('div[class=row player-sidebar-item]', 0)->childNodes(17)->children());

is not working either.也不工作。

================ FINAL UPDATE ================ ================ 最终更新 ================

After an hour researching and just trying I found the right answer!经过一个小时的研究和尝试,我找到了正确的答案!

echo $countwf = count($futhead->find('div[class=col-xs-5 player-sidebar-value]', 4)->children());

thanks for your help, I hope that people in the future benefit from the question.感谢您的帮助,我希望将来的人们从这个问题中受益。

你没有计算节点 17 的孩子,你需要调用->children()

$countwf = count($futhead->find('div.row.player-sidebar-item', 0)->childNodes(17)->children());

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

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