Skip to content

The :has() pseudo-class doesn't work #13

Description

@IoeCmcomc

Description

Both TreeDom.select() and TreeDom.select_one() failed to match any selector having the :has() pseudo-class. Because the selector parser accepts this class, this is likely to be a bug.

How to produce

Run the following code:

import markupever

html_content = """
<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>
<body>
    <div><span>Text 1</span></div>
    <div><span class="target">Text 2</span></div>
    <div><span>Text 3</span></div>
    <div><span class="target">Text 4</span></div>
</body>
</html>
"""

tree_dom = markupever.parse(html_content, "html")

print("# Start test")

for elem in list(tree_dom.select("div:has(.target)")):
    print(elem.text())

print("# End test")

Expected behaviours

The above code should print:

# Start test
Text 2
Text 4
# End test

Actual behaviours

The above code only print:

# Start test
# End test

Other information

  • Python version: 3.11.3
  • markupever version: 0.3.3

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions