Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

CSS selector with multiple :not fails #451

Closed
jonasfa opened this Issue · 12 comments
@jonasfa

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.

@uiltondutra

There is any update on this issue?

@flavorjones
Owner

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

@rb2k

Ran into this too, subscribing

@pfleidi

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

@flavorjones
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.

@LindseyB

:+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?

@knu
Owner
knu commented

I believe this has already been fixed by #887.

@knu 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'

@Mange

Yeah, I've patched this already :-(

@jackiekircher jackiekircher referenced this issue from a commit in jackiekircher/XOmBot
@LindseyB LindseyB 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
f40d9d4
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.