Skip to content

CSS3 :not() with children selectors #528

Closed

Description

@rrivas

When I attempt to use nokogiri with doc.css('.r .l:not(.mslg .l)') I receive the error

Nokogiri::CSS::SyntaxError: unexpected ' ' after '#<Nokogiri::CSS::Node:0x007fb4ab5f4940>'

I am simply trying to get urls from a google search page. This is what I'm doing

doc = Nokogiri::HTML(open("http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=Honda+Cerritos+CA"))
doc.css('.r .l:not(.mslg .l)')

Activity

  1. MatmaRex commented on Sep 4, 2011

    @MatmaRex

    This doesn't appear to be valid CSS. It doesn't work in broswer and doesn't pass the validator.

    Here's an equivalent, valid code:

    *:not(.mslg) .r .l

    Or possibly: (I'm not sure what you want - this is an exact equivalent of what I assume you meant)

    *:not(.mslg) .r:not(.mslg) .l
  2. reopened this on Sep 8, 2011
  3. rrivas commented on Sep 8, 2011

    @rrivas
    Author

    What I am attempting to do is get all of the organic urls on the google page. I am using selector gadget (http://www.selectorgadget.com/) to find an accurate path and it tells me that the path I created is an accurate CSS path.

    What I am attempting to get is the items in green (http://i.imgur.com/fQ5Jv.png). It could also be that selector gadgets paths are not working properly. I will try your suggestions.

  4. flavorjones commented on Feb 20, 2012

    @flavorjones
    Member

    This is a valid request. Currently the state of our CSS selector parsing is a bit complex, which we're planning on overhauling for the next major release.

  5. ju1ius commented on May 13, 2012

    @ju1ius
    .r .l:not(.mslg .l)

    This is not valid CSS.
    The w3c CSS3 spec allows only one simple_selector inside a :not() functional pseudo-class.
    A simple_selector is a selector that does not contain any combinator (descendant nor sibling).
    CSS4 might allow a (comma-separated) list of simple selectors, but still no combinator.
    So it's a safe bet to say that this selector will be invalid for at least the next 10 years...

  6. flavorjones commented on May 15, 2012

    @flavorjones
    Member

    My previous comment, "This is a valid request" was not referencing the CSS spec -- it was stating my opinion that there's no technological reason we couldn't support this syntax. We already support some jQuery query syntax.

  7. flavorjones commented on Jan 5, 2019

    @flavorjones
    Member

    I'm open to accepting a pull request for this functionality, but am unlikely to do that work myself. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions