pyquery icon indicating copy to clipboard operation
pyquery copied to clipboard

:not() selector throws error with multiple conditions

Open meloncholy opened this issue 11 years ago • 5 comments

The :not() selector works fine for single conditions, e.g.

doc.find('dt:not([class$="code"])')

But throws a SelectorSyntaxError: Expected ')', got <DELIM ',' at 22> error if there's a comma in the expression.

doc.find('dt:not([class$="code"], [class$="number"])')

I'm afraid I'm just flagging this up; haven't looked through the code to find out why.

(Also thanks for making this - I was struggling to traverse a (changeable) doc in BeautifulSoup before I found PyQuery, and life is now much better. :)

meloncholy avatar Mar 18 '13 21:03 meloncholy

Looks like a feature (or bug) in cssselect. @SimonSapin thoughts ?

gawel avatar Mar 18 '13 22:03 gawel

That’s how :not() works in the Selectors 3 spec, the parameter can only be a simple selector. It’s extended in Selectors 4 but that draft is not very stable yet, and not at all implemented in cssselect.

SimonSapin avatar Mar 19 '13 09:03 SimonSapin

I’m not sure if that’s what you want, but you can have two pseudo-classes in the same selector: dt:not([class$=code]):not([class$=number]) or dt:not(.code):not(.number) (the class attribute contains whitespace-separated class names.)

SimonSapin avatar Mar 19 '13 09:03 SimonSapin

@SimonSapin Ah, mea culpa. I tried it in jQuery and it worked, and assumed that this was the correct behaviour.

meloncholy avatar Mar 19 '13 10:03 meloncholy

jQuery selectors do a lot more than CSS Selectors. So far cssselect only implements Selectors Level 3 by design, but maybe that could change. Or pyquery could extend :not() (it already adds a bunch of pseudo-classes.)

SimonSapin avatar Mar 19 '13 10:03 SimonSapin