Skip to content
SCRAWL
Technical SEOFaisal Y

Custom Extraction with CSS Selectors and XPath: A Practical Guide

Fixed heading extractors stop where your audit question starts: a canonical href, a SKU in a data attribute, or JSON-LD in a script tag. Custom rules on a short URL list beat View Source on repeat.

Diagram showing three URLs feeding into CSS and XPath rules and producing a table of extracted values.
CSS and XPath rules applied to multiple page URLs
Use the free tool
CSS & XPath Extractor
Run custom CSS, XPath, or safe regex on up to 10 URLs and export CSV.

Template audits rarely fail on headings alone. They fail on the boring fields buried in HTML: a canonical pointing at staging, a meta robots left on by mistake, a product ID in a data-* attribute, or JSON-LD that still references the old brand name. View Source on ten URLs is workable. On thirty template variants after a CMS deploy, it is not.

The CSS & XPath Extractor on Scrawl fetches up to 10 URLs and runs up to 10 rules you define: CSS (cheerio), XPath (cheerio to well-formed XHTML, then a safe evaluator with limits), or regex with the same guards as Source Code Search. Output is a match table plus CSV. Raw HTML only. No JavaScript rendering.

!Flow from URL list through CSS and XPath rules to a results table

When custom rules beat fixed heading tools

Use the H1/H2 Extractor when the question is strictly heading hierarchy across up to 100 URLs. It is faster and opinionated for that job.

Use custom CSS or XPath when:

  • You need canonical URLs (link[rel=canonical] or //link[@rel='canonical']/@href)
  • You are sampling meta robots or description tags across a launch batch
  • You want one CSS class of links, not every anchor (Link Extractor is the full inventory tool)
  • You are hunting a string pattern in HTML with safe regex

After you locate JSON-LD script blocks, validate them with the Schema Checker. Extraction finds the block; schema validation checks whether it parses.

CSS selectors: start here

CSS is the fastest path for most SEO fields:

| Goal | Example rule | Attribute column |

|------|----------------|------------------|

| Canonical href | link[rel='canonical'] | href |

| Meta description | meta[name='description'] | content |

| OG title | meta[property='og:title'] | content |

| JSON-LD body | script[type='application/ld+json'] | leave empty (text) |

Run the same rules on every URL in your list. The tool does not spider your site. It only fetches what you paste.

XPath: when CSS is awkward

XPath helps when you care about attribute nodes or positional logic in messy HTML:

  • //link[@rel='canonical']/@href
  • //meta[@name='robots']/@content
  • //a[contains(@class,'affiliate')]

Guardrails in the tool:

  • Expression length cap
  • Node scan capped before values are collected; output stops at 50 matches per rule
  • Worker thread with about a 2.5 second hard timeout; invalid syntax returns a readable error
  • No eval and no arbitrary code execution

If XPath times out, narrow the expression (anchor on id or a stable container) or switch to CSS for that field.

Regex: last resort, still bounded

Regex mode reuses safe-regex validation: 200 character cap, nested quantifiers rejected, RE2 execution with a VM timeout fallback. Use it for leftover analytics IDs or CDN hostnames, not for parsing full documents.

Build a URL list

Good sources:

  • Top landing pages from analytics
  • Every URL in a sitemap segment
  • Internal URLs exported from the Link Extractor on a hub page

Keep batches at 10 URLs. For larger audits, run multiple passes and merge CSV files.

Read the match table honestly

Each row is one match for one rule on one URL. Multiple rows per URL are normal (for example several script tags). Zero rows might mean the selector is wrong, the content is injected by JavaScript, or the field truly is absent.

The tool caps match counts and value length so a runaway selector cannot return megabytes of text. If you hit caps, tighten the rule.

Worked example: canonical QA after template deploy

You shipped a new product template. You want every canonical to self-reference on HTTPS.

  1. List ten representative product URLs.
  2. Add a CSS rule: link[rel='canonical'] with attribute href.
  3. Run extraction. Scan the value column for staging hostnames or HTTP URLs.
  4. Download CSV for the ticket.
  5. Spot-check one outlier in DevTools.

Mistakes that waste time

  • Expecting SPA-only fields without server HTML.
  • Using this tool for every anchor when Link Extractor already exports rel flags and CSV.
  • Duplicating H1/H2 audits. The heading extractor is the right fixed tool.
  • Huge XPath on minified pages. Prefer CSS or a shorter path.

Run your rules

Paste URLs, add CSS or XPath rules, and run the CSS & XPath Extractor. Export CSV when you need evidence in a launch checklist or client sign-off.

css selectorxpathhtml extractiontechnical seo

Related Articles

Frequently Asked Questions

When should I use custom CSS or XPath instead of the H1/H2 Extractor?

Use the H1/H2 Extractor when you only need heading tags across many URLs. Use custom CSS or XPath when the field is a meta tag, canonical link, data attribute, or any selector you define.

Does extraction run JavaScript?

No. Only the initial HTML response is parsed.

How many URLs and rules can I run?

Up to 10 URLs and 10 rules per run on Scrawl's CSS & XPath Extractor.

Is XPath safe to run server-side?

Expressions are length-capped, node counts are capped, and evaluation runs in a worker with a hard timeout. Invalid XPath returns an error. The tool does not use eval.

Can I export matches?

Yes. Download CSV with url, rule, type, index, value, and attribute columns.