簡體   English   中英

Simple HTML Dom:選擇和計數子元素(.eq 函數到 Simple HTML Dom)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM