Skip to content
This repository

CSS selector with multiple :not fails #451

Closed
jonasfa opened this Issue · 12 comments

12 participants

Jonas Alves Uilton Dutra Mike Dalessio Marc Seeger Sven Pfleiderer Victor Morandini Stabile Lindsey Bieda Scott Bartell wakiki Akinori MUSHA hwo411 Magnus Bergmark
Jonas Alves

Trying to use the following CSS selector raises an Nokogiri::CSS::SyntaxError exception: *:not(.one):not(.two)

This page from w3.org uses the following similar selector as an example: *:not(.txt_escuro):not(.fotoMateria), so it should be valid.

Uilton Dutra

There is any update on this issue?

Mike Dalessio
Owner

We're discussing overhauling CSS selector parsing for the next major release. Nothing is likely to happen very soon, unfortunately. :(

Marc Seeger
rb2k commented

Ran into this too, subscribing

Sven Pfleiderer

I ran into this problem, too. Has there been any progress so far?

Mike Dalessio
Owner

We're targeting overhauling CSS selector parsing for the next major release (i.e., Nokogiri 2.0). Nothing is likely to happen before summer.

Victor Morandini Stabile

+1

Lindsey Bieda

:+1: I've ran into this today. I ended up working around it using XPATH selectors instead of CSS.

wakiki

+1

any updates on this?

Akinori MUSHA
Owner
knu commented

I believe this has already been fixed by #887.

Akinori MUSHA knu closed this
hwo411

Still not fixed. I used it in the following way:

page.css('.someclass tr:not(:nth-child(1)):not(:nth-child(2))')

also I tried

page.css('.someclass tr:not(:nth-child(1)):nth-child(2)')

which not works too
but

page.css('.someclass tr:nth-child(2):not(:nth-child(1))')

works

logs:

for page.css('.someclass tr:not(:nth-child(1)):not(:nth-child(2))')

2014-03-15 17:00:40.490 ERROR: Nokogiri::CSS::SyntaxError: unexpected ':not(' after '[#<Nokogiri::CSS::Node:0x00000000f70a30 @type=:DESCENDANT_SELECTOR, @value=[#<Nokogiri::CSS::Node:0x00000000f72038 @type=:CONDITIONAL_SELECTOR, @value=[#<Nokogiri::CSS::Node:0x00000000f72330 @type=:ELEMENT_NAME, @value=["*"]>, #<Nokogiri::CSS::Node:0x00000000f72880 @type=:CLASS_CONDITION, @value=["someclass"]>]>, #<Nokogiri::CSS::Node:0x00000000f70cd8 @type=:CONDITIONAL_SELECTOR, @value=[#<Nokogiri::CSS::Node:0x00000000f71868 @type=:ELEMENT_NAME, @value=["tr"]>, #<Nokogiri::CSS::Node:0x00000000f70d28 @type=:NOT, @value=[#<Nokogiri::CSS::Node:0x00000000f70f30 @type=:PSEUDO_CLASS, @value=[#<Nokogiri::CSS::Node:0x00000000f712c8 @type=:FUNCTION, @value=["nth-child(", "1"]>]>]>]>]>]'
2014-03-15 17:00:40.490 ERROR: /home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/css/parser_extras.rb:87:in on_error'
/home/hwo411/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/racc/parser.rb:258:in
_racc_do_parse_c'
/home/hwo411/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/racc/parser.rb:258:in do_parse'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/css/parser_extras.rb:62:in
parse'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/css/parser_extras.rb:79:in xpath_for'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/css.rb:23:in
xpath_for'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb:211:in block in css'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb:210:in
map'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb:210:in `css'

and

for page.css('.someclass tr:not(:nth-child(1)):anyselector')

2014-03-15 17:05:07.358 ERROR: Nokogiri::CSS::SyntaxError: unexpected ':' after '[#<Nokogiri::CSS::Node:0x000000012e87a8 @type=:DESCENDANT_SELECTOR, @value=[#<Nokogiri::CSS::Node:0x000000012e99c8 @type=:CONDITIONAL_SELECTOR, @value=[#<Nokogiri::CSS::Node:0x000000012e9a40 @type=:ELEMENT_NAME, @value=["*"]>, #<Nokogiri::CSS::Node:0x000000012e9f18 @type=:CLASS_CONDITION, @value=["someclass"]>]>, #<Nokogiri::CSS::Node:0x000000012e88e8 @type=:CONDITIONAL_SELECTOR, @value=[#<Nokogiri::CSS::Node:0x000000012e9590 @type=:ELEMENT_NAME, @value=["tr"]>, #<Nokogiri::CSS::Node:0x000000012e8960 @type=:NOT, @value=[#<Nokogiri::CSS::Node:0x000000012e8cf8 @type=:PSEUDO_CLASS, @value=[#<Nokogiri::CSS::Node:0x000000012e8de8 @type=:FUNCTION, @value=["nth-child(", "1"]>]>]>]>]>]'
2014-03-15 17:05:07.358 ERROR: /home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/css/parser_extras.rb:87:in on_error'
/home/hwo411/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/racc/parser.rb:258:in
_racc_do_parse_c'
/home/hwo411/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/racc/parser.rb:258:in do_parse'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/css/parser_extras.rb:62:in
parse'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/css/parser_extras.rb:79:in xpath_for'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/css.rb:23:in
xpath_for'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb:211:in block in css'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb:210:in
map'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb:210:in `css'

Magnus Bergmark
Mange commented

Yeah, I've patched this already :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.