Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

クローズ
#190 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@AdrianAtZyte がすでに取り組んでいます。

2026年8月7日 から。

  • #179 @AdrianAtZyte による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
web-dev

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
311
フォーク
73
平均マージ
2日 24分
マージ済み PR(30日)
11

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

scrapy/cssselect のほかの issue

scrapy/cssselect の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。