Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usage of near child (> operator) not working #102

Open
scorninpc opened this issue Jun 22, 2023 · 1 comment
Open

usage of near child (> operator) not working #102

scorninpc opened this issue Jun 22, 2023 · 1 comment

Comments

@scorninpc
Copy link

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

When find for > span for example, throw a error Expected selector, but " at 0> found.

In the code above, first echo show real 29.30 nodes fine, but second one need to return just 29.30

How can I reproduce it?

$find = (new \voku\helper\HtmlDomParser())->loadHtml(<<<EOD
	<html>
		<body>
			<div class="card-action-item"></div>
			<div class="card-action-item">
				real <span>29.30</span> <span> nodes</span>
			</div>
		</body>
	</html>
EOD);

$find = $find->find(".card-action-item:nth-child(2)", 0);
$all = $find->text;
echo $all . "\n";

$find = $find->find("> span");
$just_value = $find->text;
echo $just_value . "\n";

Any additional information?

I have tested on another languages, and this may be a valid selector. am I doing something wrong?

@scorninpc
Copy link
Author

scorninpc commented Jun 23, 2023

As we can use xpath to create a selector too, enable axes can help (#103)

with this change, we can use something like this

$find = (new \voku\helper\HtmlDomParser())->loadHtml(<<<EOD
	<html>
		<body>
			<div class="card-action-item"></div>
			<div class="card-action-item">
				real <span>29.30</span> <span> nodes</span>
			</div>
		</body>
	</html>
EOD);

$find = $find->find(".card-action-item:nth-child(2)", 0);
$all = $find->text;
echo $all . "\n";  // print real 29.30 nodes

$find = $find->find("child::span");
$just_value = $find->text;
echo $just_value . "\n"; // print 29.30

if @voku accept the idea, i can implement another ones https://www.w3schools.com/xml/xpath_axes.asp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant