Tools
CSS and XPath selector tester: paste HTML, see every match
Test a CSS selector or XPath expression against pasted HTML in your browser. Shows match counts and the matched markup, with no server round trip.
Loading tool…
The tool runs in your browser. It is loading now.
This tool runs a CSS selector or XPath expression against HTML you paste. It uses the browser’s own parser and query engine, so the result matches what a browser sees, not what a Python library might see. Nothing is uploaded.
How to use it
- Paste the HTML you want to query.
- Enter a CSS selector such as
article.card h2or an XPath expression such as//article[contains(@class,"card")]//h2. - Switch the syntax selector between CSS and XPath.
- Read the match count and the first eight matches.
CSS vs XPath
- CSS is shorter for tag, class, id, attribute, and descendant matches. It is the right default.
- XPath is better when the position or text of a nearby element determines the target, such as “the cell after the header that says Price”.
The CSS and XPath lesson covers the patterns and the pitfalls.
Limits
- The tool uses the browser’s HTML parser. Python’s
html.parser,lxml, andselectolaxmay repair malformed HTML differently. - It shows the first eight matches; a page with 1,000 matches is truncated in the preview.
- It does not execute JavaScript. If the content is client-rendered, paste the rendered DOM or use a browser automation tool.
- XPath support depends on the browser;
document.evaluateimplements the standard subset.
A good selector checklist
- Anchor on the smallest stable container.
- Prefer semantic attributes over generated classes.
- Test on more than one page of the same type.
- Fail loudly if the match count is zero.
- Store a fixture and the expected output in a test.