[英]Simple HTML Dom: Select and count child element (.eq function to Simple HTML Dom)
我似乎无法将 DOM 语言翻译成 Simple HTML DOM 语言。 这是 Google Chrome 控制台上的正确解决方案:
$('div.row.player-sidebar-item', 0).children().eq(17).children().length;
//console answer: 4
并在此给出正确答案,但我需要使用简单的 HTML DOM 来完成,但找不到任何相关信息。 此代码还返回我需要的信息:
$('div.col-xs-5.player-sidebar-value', 0).eq(4).children().length;
//console answer: 4
我不知道如何在 Simple HTML DOM 中执行此操作,因此我的代码直到现在:
$countwf = count($futhead->find('div.row.player-sidebar-item', 0)->childNodes(17));
这是我能做到的最好的,我不知道如何做得更好。 我希望有一个人可以帮助我。
================ 第一次更新 ================
在第一条评论之后,我试过这个:
echo $countwf = count($futhead->find('div[class=col-xs-5 player-sidebar-value]', 0)->childNodes(4)->children());
这不起作用,
echo $countwf = count($futhead->find('div[class=row player-sidebar-item]', 0)->childNodes(17)->children());
也不工作。
================ 最终更新 ================
经过一个小时的研究和尝试,我找到了正确的答案!
echo $countwf = count($futhead->find('div[class=col-xs-5 player-sidebar-value]', 4)->children());
感谢您的帮助,我希望将来的人们从这个问题中受益。
你没有计算节点 17 的孩子,你需要调用->children()
$countwf = count($futhead->find('div.row.player-sidebar-item', 0)->childNodes(17)->children());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.