Scraping API Prices
MenuClose

Search the site

82 providers, their alternatives and head-to-heads, targets, guides and answers

Home / Tools / CSS selector and XPath tester

CSS selector and XPath tester

Paste the HTML a scraping API returned and type a CSS selector or an XPath expression: every element it matches is listed, with its text, so you can fix the selector before the scraper runs on thousands of pages.

3 elements match .product .price

  1. span.price $89.00
  2. span.price $129.00
  3. span.price $18.00

Worked out in your browser. Nothing you paste is stored, sent or added to the page address, so tokens and cookies stay on your machine.

What it is for when you scrape

A scraper is only as good as its selectors. A selector that matches one element too many, or none after a site changes its markup, fills a dataset with wrong values or blanks, and every one of those pages was still a paid request. Test against the HTML the API actually returns, not the page in your browser: a page fetched without JavaScript can be missing everything a script adds.

An expression that starts with / or ( is read as XPath; anything else as a CSS selector. XPath can select by text and walk up the tree (//h2[contains(., "socks")]/..), which CSS cannot; CSS is shorter for classes and attributes.

Pages that need rendering cost several times a plain request on most APIs; what JavaScript rendering adds shows the multiple on each, so check whether the elements you want are in the plain HTML first.