voku / simple_html_dom

📜 Modern Simple HTML DOM Parser for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is possible to implement :parent ?

scorninpc opened this issue · comments

What is this feature about (expected vs actual behaviour)?

I know thats exists parent() method, but its possible to implement that on selector, like this https://api.jquery.com/parent-selector/ ?

How can I reproduce it?

when use $dom->findOne('.details > div:nth-child(4) > div b:contains("Local"):parent'); throw exception: Pseudo-class "parent" not supported.

I dont know if this is the best solution, but it's a ideia, as the pseudo selector doesn't work

$find = new \voku\helper\HtmlDomParser($html);

// explode the :parent
$parents = explode(":parent", $selector);

// loop between parts
foreach($parents as $index => $sel) {
  $find = $find->findOne($sel);
  $find = $find->parent();
}
$result = $find->text;

what do you guys think?

Mostly we depend on CssSelector (a Symfony Component that Converts CSS selectors to XPath expressions) here. And pseudo selectors are only partly supported. Maybe we could Hck something with the parent method (did it work for you)? But in most cases I would try to avoid this special selectors, if possible.