简体   繁体   English

如何使用PHP Simple HTML DOM Parser查找具有特定子元素的元素?

[英]How to find an element that has a specific child with PHP Simple HTML DOM Parser?

I need to find all tr that has a td child with a specific bgcolor. 我需要找到所有具有特定bgcolor的td子的tr

Is it possible with PHP Simple HTML Dom Parser? PHP Simple HTML Dom Parser是否有可能?

I can get all td with the next sentence: 我可以在下一句话中得到所有td

$cells = $html->find ( "tr td[bgcolor=#3366FF]" ); $ cells = $ html-> find(“ tr td [bgcolor =#3366FF]”);

But I need the tr instead of the td . 但是我需要tr而不是td I don't know if it is possible to find ascendant elements. 我不知道是否有可能找到上升的元素。

Thank you! 谢谢!

according to the documentation: http://simplehtmldom.sourceforge.net/manual_api.htm 根据文档: http : //simplehtmldom.sourceforge.net/manual_api.htm

parent() should work. parent()应该可以工作。

foreach($html->find('td[bgcolor=#3366FF]') as $element) {
    $element->parent() etc...

This should work to have tr... 这应该工作有...

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

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