pyquery
pyquery copied to clipboard
:not() selector throws error with multiple conditions
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. :)
Looks like a feature (or bug) in cssselect. @SimonSapin thoughts ?
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.
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 Ah, mea culpa. I tried it in jQuery and it worked, and assumed that this was the correct behaviour.
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.)