scrapy / scrapy/cssselect

[feature-request] `:not()` to support generic selectors (not only "simple" ones)

Open
#51 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

CSS Selectors Level 4
Dominant language
Python
Stars
310
Forks
70
Avg merge
2h 9m
Merged PRs (30d)
4

Description

The document (version 0.9.1) says:

:not() accepts a sequence of simple selectors, not just single simple selector. For example, :not(a.important[rel]) is allowed, even though the negation contains 3 simple selectors.

May I ask what is a simple selector? Can :not() support something like :not(a>b)?

>>> import cssselect
>>> cssselect.parse('a:not(p>a)')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/cssselect/parser.py", line 355, in parse
    return list(parse_selector_group(stream))
  File "/usr/lib/python3.4/site-packages/cssselect/parser.py", line 370, in parse_selector_group
    yield Selector(*parse_selector(stream))
  File "/usr/lib/python3.4/site-packages/cssselect/parser.py", line 378, in parse_selector
    result, pseudo_element = parse_simple_selector(stream)
  File "/usr/lib/python3.4/site-packages/cssselect/parser.py", line 471, in parse_simple_selector
    raise SelectorSyntaxError("Expected ')', got %s" % (next,))
cssselect.parser.SelectorSyntaxError: Expected ')', got <DELIM '>' at 7>

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with cssselect.parse('a:not(p>a)'). Start in cssselect/parser.py at parse, parse_selector_group, and parse_simple_selector, which appear in the traceback. Done means the requested generic selector form is accepted by :not() without the shown syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.