Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Unable to Correctly Parse `:has()` Pseudo-Classes with More than a Singular Child

Chiusa
#190 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@AdrianAtZyte ci sta già lavorando.

Dal 7/8/2026.

  • #179 di @AdrianAtZyte — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
web-dev

Direzione di ricerca

Start at the GenericTranslator().css_to_xpath entry point and reproduce the three :has() examples from the issue. Trace how :has() arguments are parsed, especially attribute selectors and descendant selectors. Done means these arguments translate successfully while the existing singular-tag and combinator cases continue to work.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Issue

When attempting to parse a CSS selector using a :has pseudo-class, it works but only if a singular tag name is provided.

For example, if selecting for a child with attributes:

>>> from cssselect import GenericTranslator
>>> GenericTranslator().css_to_xpath('h4.my-class:has(a[href^="/rel"])')
*** cssselect.parser.SelectorSyntaxError: Expected an argument, got <DELIM '[' at 17>

Likewise, if attempting to select for a tag with a descendant tag, we get:

>>> GenericTranslator().css_to_xpath('h4.my-class:has(div a')
*** cssselect.parser.SelectorSyntaxError: Expected an argument, got <IDENT 'a' at 20>

However, selecting for a singular tag name works:

>>> GenericTranslator().css_to_xpath('h4.my-class:has(a)')
"descendant-or-self::h4[(@class and contains(concat(' ', normalize-space(@class), ' '), ' my-class ')) and (descendant::a)]"

Diagnosing it further, this also does not affect combinators inside the :has(...):

>>> GenericTranslator().css_to_xpath('h4.my-class:has(> a)')
"descendant-or-self::h4[(@class and contains(concat(' ', normalize-space(@class), ' '), ' my-class ')) and (./a)]"

Information

Running cssselect version 1.5.0.

Lingua principale
Python
Stelle
312
Fork
72
Merge medio
2g 24m
PR unite (30g)
11

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scrapy/cssselect

Tutte le issue di scrapy/cssselect

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.