Scrapling & Advanced Web Scraping
This skill provides advanced patterns for web scraping using Scrapling, a high-performance framework, and its underlying engine Parsel. It is designed for stealthy data extraction and building crawlers that survive website design changes.
Core Engines
1. Scrapling (High-Performance & Stealth)
Ideal for environments with full browser support (Linux/Windows/macOS).
- StealthyFetcher: Bypasses anti-bot systems like Cloudflare.
- Adaptive Parser: Automatically finds elements if CSS selectors change.
- Spider Framework: Concurrent, multi-session crawling.
2. Parsel (Lightweight & Versatile) - LOCAL RECOMMENDED
Recommended for Termux and lightweight environments. It uses CSS and XPath selectors (like Scrapling and Scrapy) but without the heavy browser dependency.
- Speed: Extremely fast (built on LXML).
- Flexibility: Supports CSS, XPath, and Re (Regex) selectors in one chain.
Usage Patterns
Adaptive Scraping (Scrapling)
Use this when you need the script to be robust against site updates.
from scrapling.fetchers import StealthyFetcher
fetcher = StealthyFetcher()
page = fetcher.fetch('https://example.com')
# Use adaptive=True to enable element relocation on failure
title = page.css('h1.title::text', adaptive=True).get()
Lightweight Scraping (Parsel)
Best for Termux. Fast and reliable.
import requests
from parsel import Selector
response = requests.get('https://example.com')
sel = Selector(text=response.text)
# Extract multiple items
items = sel.css('div.item')
for item in items:
name = item.css('h2::text').get()
price = item.xpath('.//span[@class="price"]/text()').get()
Anti-Bot Guidance
If you encounter "Access Denied" or Cloudflare:
- User-Agent: Always rotate or set a realistic User-Agent.
- Scrapling Stealth: Use
StealthyFetcherif available. - Cloudscraper: Use
cloudscraperas a drop-in replacement forrequests.
See REFERENCES.md for more advanced patterns and anti-bot techniques.