CSS selector or XPath — which should you use for scraping?
Both reach the same elements; the difference is ergonomics. CSS selectors are shorter and
cover 95% of scraping needs (.price, div#main a[href^="/item"]).
XPath wins when you need to select by text content
(//a[contains(text(),"Next")]), walk up the tree
(/../..), or grab text nodes and attributes directly
(//span/@data-id). This tester supports both, so you can compare them on the
same HTML.
Quick reference
| Goal | CSS selector | XPath |
|---|---|---|
| Element by class | .price | //*[@class="price"] |
| Element by id | #main | //*[@id="main"] |
| Direct child | ul > li | //ul/li |
| Attribute value | a[href] (element only) | //a/@href |
| Contains text | — not possible | //a[contains(text(),"Next")] |
| Nth match | li:nth-child(3) | (//li)[3] |
| Parent element | — not possible | //span[@class="price"]/.. |
Why use this tester?
- One tool for both syntaxes with auto-detection — no tab-switching between separate testers.
- Real scraper code generation for BeautifulSoup, parsel, Scrapy, Cheerio and Playwright — not just a match list.
- Private: your HTML is parsed by your own browser and never uploaded — unlike server-side testers.
- No ads, no vendor upsell, no login.
Frequently asked questions
How do I test a CSS selector against my own HTML?
Paste your HTML in the left box and type a selector like div.product > h2 a in the selector field. Matches appear instantly with a count, and you can view the matched elements as text, HTML, or a specific attribute value.
Does this tool support XPath?
Yes. Switch the mode to XPath (or leave it on Auto — expressions starting with /, ./ or ( are detected as XPath automatically) and write expressions like //div[@class="price"]/text(). Evaluation uses the browser’s native XPath engine (XPath 1.0), the same one Scrapy and lxml users target most often.
Can I get scraper code for my selector?
Yes — once your selector matches, the tool generates ready-to-run snippets for Python (BeautifulSoup and lxml/parsel), Scrapy, JavaScript (Cheerio) and Playwright, with your selector and HTML-handling boilerplate filled in.
Is my HTML uploaded to a server?
No. Parsing and matching run entirely in your browser using its built-in HTML parser. Nothing you paste leaves your device — you can even load the page and then go offline.
Why does my selector work here but not in my scraper?
The most common reason: your scraper fetches raw HTML, but the content you see in DevTools was added by JavaScript after page load. Test against the HTML your scraper actually receives (e.g. from response.text), not the DevTools DOM. Also note that browser parsers auto-insert elements like <tbody>, which affects XPath paths.