When to Use
Generic extractors fail or extract wrong content
Site has unique/non-semantic HTML structure
Need to extract custom fields (price, rating, category)
E-commerce, job boards, real estate, forums
Configuration
For Article Content
UseCUSTOM_SELECTORS in settings:
For Structured Data
Use callbacks for non-article content:CSS Selector Syntax
Basic Selectors
Extract Text
Extract Attributes
Multiple Matches
["WiFi", "Bluetooth", "GPS"]
Standard vs Custom Fields
Standard Fields (Database Columns)
Map directly toscraped_items table:
title→ scraped_items.titlecontent→ scraped_items.contentauthor→ scraped_items.authordate→ scraped_items.published_date
Custom Fields (Metadata JSON)
Any other field names stored inmetadata_json:
price,rating,category,brand, etc.- Displayed in
showcommand - Flattened in exports
Selector Discovery Workflow
Step 1: Inspect Page
data/proj/spider/analysis/page.html
Step 2: Analyze Structure
- h1/h2 elements with classes
- Content containers by size
- Date elements
- Author elements
Step 3: Test Selectors
Step 4: Search for Fields
Step 5: Test on Multiple Pages
Selector Best Practices
Target main content element (not navigation/sidebar/footer)
Selector should match ONE element per page
Prefer specific classes (
.article-title) over generic (.title)Test on multiple pages to verify consistency
Prefer semantic tags (
<article>, <time>, <h1>)Content selector should return >500 chars; title >10 chars
Examples
News Article
E-commerce Product
Forum Thread
Validation
Custom extractor requires title (min 5 chars) and content (min 100 chars). If validation fails, returnsNone and tries next extractor (if configured).
Fallback Strategy
Recommended: Use custom with fallback to genericDebugging
Test selectors using:- Selector doesn’t match element (typo in class name)
- Content too short (selector targets sidebar instead of main content)
- Wrong content extracted (selector too generic, matches multiple elements)
Related
- Callbacks - Complete callback schema with processors
- Extractors Overview - Strategy selection
- Newspaper Extractor - Generic news extractor
- Trafilatura Extractor - Generic content extractor
- Settings - Configuration options