XPath Tester
Test XPath expressions against HTML/XML
Paste HTML or XML, write an XPath expression, and see which nodes it matches. XPath trips people up more than CSS selectors do — a missing / or wrong axis is hard to catch without something to test against. Works with XPath 1.0, which is what Scrapy, lxml, and most Python scraping libraries use under the hood.
No input provided
How to use
- 1Paste HTML or XML — Any fragment works. XML with namespaces is supported too.
- 2Write an expression — Enter an XPath expression. For example: //div[@class="price"] or //a/@href.
- 3Get results — In auto mode, matches update as you type. Disable auto mode to run manually with Run.
- 4Use axes for complex queries — parent::, ancestor::, following-sibling:: — for traversing the tree sideways and upward, which CSS cannot do.
Examples
//a/@href//div[@class="product-title"]//p[contains(text(), "price")]//li[.//span[@class="badge"]]/a(//ul[@class="results"]/li)[3]When to use for web scraping
XPath is indispensable in two cases where CSS falls short: when you need to find an element by its descendant's text (for example, a table cell next to a "Price" cell), and when you need to navigate up the DOM tree. In Python, XPath 1.0 is supported natively via lxml and Scrapy (response.xpath()). In Node.js — via xmldom and xpath. The tool runs XPath 1.0 — the same version used by these libraries. Typical workflow: get HTML via Request Tester, open it here, write your expression and confirm it returns the right nodes — then copy to your code without surprises.