Quick Start

Build your first XPath expression in three steps.

1. Import the essentials

from xpath_builder import E, STAR, Pred

2. Build an expression

# Find all divs with class containing "container"
xpath = E("div").any().where(
    Pred.attr("class").contains.any_of("container")
)

3. Compile to a string

print(xpath.compile())
# //div[contains(@class, 'container')]

The general pattern is: create a nodeset an axisadd predicatescompile.