Skip to content
Happy Endpoint
Web Scraping

XPath

Definition updated April 2026

What is XPath?

XPath (XML Path Language) is a query language for navigating XML and HTML documents and selecting nodes. It expresses the path to elements using a syntax similar to file system paths, and supports conditions, functions, and predicates that make it more expressive than CSS selectors for complex extraction tasks.

XPath can select elements based on their text content (//div[contains(text(), 'Price')]), navigate up to parent elements, and select the Nth occurrence of an element - operations that are difficult or impossible with CSS selectors alone. It is supported natively by lxml in Python and by most XML processing tools.

XPath is more powerful than CSS selectors but also more verbose and harder to read. For most web scraping tasks, CSS selectors are preferred for their simplicity; XPath is reached for when the required traversal logic exceeds what CSS can express.

Ready to work with live data?

HappyEndpoint APIs deliver real-world data from leading platforms - no scraping, no stale snapshots.

Browse Datasets