ivopetkov / html5-dom-document-php

A better HTML5 parser for PHP.
MIT License
599 stars 40 forks source link

Selectors with spaces #22

Closed Tam closed 5 years ago

Tam commented 6 years ago

I'm trying to query for elements using selectors from a stylesheet. The majority of the have spaces in, but when I try to query by them I get this error: Unsupported selector (div .my-thing).

The docs don't mention anything about spaces, so I assume they're not supported? Is it possible to add support, or is there a workaround I could use?

ivopetkov commented 6 years ago

Sure, I'll add support in a couple of days.

Tam commented 6 years ago

Awesome, thanks! Do you have any plans to add advanced CSS selector support (i.e. .my-list > li:nth-child(1n + 3)) or is this something I'd have to handle manually?

ivopetkov commented 6 years ago

It would be great to add such selectors, but I'm short on time the following weeks (I'll do selectors with spaces though). Are you interested in writing the code yourself? I will help with architecture and code optimization if needed.

Tam commented 6 years ago

I'm certainly up for it, but I'm also super busy over the next few weeks! I'll see if I can find some time to look into it.

AndresSepar commented 6 years ago

@Tam You can solve it using the querySelector in this way:

$dom->querySelector('.parent')->querySelectorAll('.children')
ivopetkov commented 5 years ago

Just released v1.1.0 with support for selectors with spaces... and some more :)