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

Already on GitHub? Sign in to your account

CSS selector with multiple :not fails #451

Closed
jonasfa opened this Issue Apr 29, 2011 · 12 comments

Comments

Projects
None yet

jonasfa commented Apr 29, 2011

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.

There is any update on this issue?

Owner

flavorjones commented Feb 20, 2012

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

rb2k commented Apr 23, 2012

Ran into this too, subscribing

pfleidi commented Apr 23, 2012

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

Owner

flavorjones commented Apr 23, 2012

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

+1

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

👍

wakiki commented Aug 1, 2013

+1

any updates on this?

Owner

knu commented Aug 1, 2013

I believe this has already been fixed by #887.

@knu knu closed this Aug 1, 2013

hwo411 commented Mar 15, 2014

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:inparse'
/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:inxpath_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:inmap'
/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:inparse'
/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:inxpath_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:inmap'
/home/hwo411/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/lib/nokogiri/xml/node.rb:210:in `css'

Contributor

Mange commented Mar 15, 2014

Yeah, I've patched this already :-(

jackiekircher pushed a commit to jackiekircher/XOmBot that referenced this issue Aug 17, 2014

FUCK YOU TWITTER!!!!
After the twitter gem and API have proven to be flawed and unreliable
I've decided to remove gut it.

I've resorted to screenscraping for tweets. I'm not proud of it,
It works, however, and I am losing zero functionality. Though, responce
times will be slower since instead of fetching a tiny JSON object the
entire web page is being fetched and then parsed with nokogiri. I'm
doing some magic with XPATH since, unfortunately, nokogiri did not
like me having two nots in my css selectors.

Note the relevant ticket: sparklemotion/nokogiri#451
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment