Sub topic 14
Extracting custom data with XPath, CSS path and regex
This chapter assumes you can run a basic crawl and read the Internal tab. It also assumes you know HTML structure well enough to find an element in your browser's inspector.
What custom extraction does
The SEO Spider reports standard elements such as titles and canonicals. Custom extraction collects anything else from each page's HTML. Examples are Open Graph tags, product SKUs, author names, and the date a page was last updated.
You set it up under Configuration > Custom > Extraction. Each extractor has a name, a method, an expression, and an extract option. Results appear in the Custom Extraction tab and in the Internal tab export.
Choosing a method
| Method | Best for | Notes |
|---|---|---|
| XPath | Elements and attributes anywhere in the document | Most flexible. Can return an attribute with `/@name`. |
| CSS Path | Simple selections by tag, class or ID | Easier to write if you know CSS. Has an attribute option for returning values such as `content`. |
| Regex | Text inside scripts, JSON-LD or comments | Must contain one capture group. Only the group is returned. |
Pick XPath or CSS Path when the data sits in a normal element. Use regex only when the data is not in a clean element, for example inside an inline script.
Writing the expressions
This XPath returns the Open Graph title from every page, so you can compare it with the page title.
//meta[@property='og:title']/@contentThe CSS Path version selects the same element. Set the attribute option to content in the extractor.
meta[property="og:title"]This regex pulls a product SKU out of inline JSON. The parentheses create the capture group, and the crawler returns only the text inside them.
"sku":\s*"([A-Z0-9-]+)"Setting up an extractor
- Open Configuration > Custom > Extraction.
- Add an extractor and give it a clear name, such as
og_title. - Choose XPath, CSS Path or Regex and paste the expression.
- Choose what to extract: the HTML element, the inner HTML, the text, or the function value.
- Use a single page's source to confirm the expression matches before you crawl.
- Run the crawl, then open the Custom Extraction tab.
Common errors
- Empty column: the expression matches nothing in the raw HTML. Check the page source, not the inspector, which shows the rendered DOM.
- Regex returns nothing: you left out the capture group.
- Quotes break the expression: curly quotes pasted from a document are not valid. Use plain quotes.
- Too many results: a loose selector such as
//metamatches every meta tag. Narrow it with an attribute.
Test on a small crawl first. Limit the crawl with an include rule so you can fix mistakes quickly.
Exercise
Your regex "sku":\s*"[A-Z0-9-]+" matches on a page, but the Custom Extraction column is empty. What is wrong, and how do you fix it?
Show answer
The regex has no capture group, and the SEO Spider returns only the text inside a group. Wrap the part you want in parentheses: "sku":\s*"([A-Z0-9-]+)".