Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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
Closed

CSS selector with multiple :not fails #451

jonasfa opened this issue Apr 29, 2011 · 12 comments

Comments

@jonasfa
Copy link

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.

@uiltondutra
Copy link

There is any update on this issue?

@flavorjones
Copy link
Member

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

@rb2k
Copy link

rb2k commented Apr 23, 2012

Ran into this too, subscribing

@pfleidi
Copy link

pfleidi commented Apr 23, 2012

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

@flavorjones
Copy link
Member

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

@vstabile
Copy link

+1

@LindseyB
Copy link

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

@scottbartell
Copy link

👍

@wakiki
Copy link

wakiki commented Aug 1, 2013

+1

any updates on this?

@knu
Copy link
Member

knu commented Aug 1, 2013

I believe this has already been fixed by #887.

@knu knu closed this as completed Aug 1, 2013
@hwo411
Copy link

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'

@Mange
Copy link
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
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests