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

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.

Related Articles

Technical SEO

Site migration SEO checklist

Most migrations don't fail because someone forgot a "best practice." They fail because one boring th…

Technical SEO

Technical SEO audit checklist

Most technical audits start in the wrong place. Someone opens a crawler, exports 4,000 "issues," and…

Tool Guides

SEO readiness checker: score any URL, fix what matters

Most technical audits start with a 4,000-row crawl export. You need something faster: is this one UR…

Technical SEO

How to Check if a Page Is Indexed by Google (and Fix It If Not)

Pages outside Google's index cannot rank. Learn what "indexed" means, how to confirm status in Searc…

Technical SEO

What Is PageRank in 2026? How Google Link Authority Works (and How to Check It)

Google retired public PageRank in 2016, but links still matter for discovery and relevance. Here's h…

Technical SEO

Broken link checker: find 404s on a page, check URL lists in bulk, and fix the right links

A broken link is a link that leads nowhere useful. Usually that means a 404, sometimes a 410, a serv…

Technical SEO

Bulk status checker: audit up to 200 URLs for 404s, redirects, and server errors

A bulk status check answers one question: for each URL in this list, what does the server return rig…

Technical SEO

How to see which AI crawlers visit your site in your server logs

robots.txt states what you want crawlers to do. Access logs show what actually hit your server: whic…

Technical SEO

How to check whether AI search bots can crawl your pages

A page can look fine in Chrome and still be a thin shell in raw HTML. AI retrieval crawlers mostly r…

Technical SEO

Automated Accessibility Checks: What They Catch and What They Miss

A clean automated report does not mean your page is accessible. Static HTML rules catch missing name…

Technical SEO

Soft 404s: How to Find Them and Why Google Flags Them

A soft 404 can mislead crawlers and users when missing URLs return the wrong HTTP status. Learn what…

Technical SEO

Indexability: How to Check If a Page Can Be Indexed

Learn whether a page can be indexed from server signals before you ask why Google excluded it. Statu…

Technical SEO

Googlebot Simulator: Compare Googlebot vs Browser Fetches

Learn when to compare Googlebot and Chrome fetches, how to read a side-by-side diff, and what Scrawl…

Technical SEO

How to Find Any Site's XML Sitemap

Learn where sitemaps usually live, how robots.txt Sitemap lines work, and how to discover index and…

Technical SEO

Mixed Content: How to Fix HTTP on HTTPS

Mixed content is an HTTPS page requesting an HTTP script, stylesheet, image, or font. Here is what b…

On-Page SEO

What Is a PAA Box? How People Also Ask Works in Google Search

A PAA box is the People Also Ask list Google shows for many searches: related questions that open in…

Technical SEO

Robots.txt Explained: How Allow, Disallow and Wildcards Really Work

Robots.txt tells crawlers which URLs they may fetch. It does not remove pages from Google's index by…

On-Page SEO

Google AI Overviews: What They Are and How to Get Your Content Cited

AI Overviews are Google's generated answer blocks on some searches. They cite a small set of sources…

Technical SEO

Schema Checker Guide: How to Validate JSON-LD and Microdata

A schema checker reads the structured data on a page and tells you whether a machine can parse it an…

Technical SEO

How to Write and Fix llms.txt for AI Discovery

llms.txt is a markdown index at your site root that names your project, summarizes it in one line, a…

Technical SEO

Hreflang Implementation Guide: HTML, Headers, and Sitemap

Hreflang tells search engines which URL to show for each language or region. Here is how to implemen…

Technical SEO

Redirect rules for migrations: plan the map, write the config

A migration lives or dies on redirects. Build the URL map first, choose the right status code, then…