Cookbook & Recipes

Production-ready, battle-tested code recipes for common web scraping and crawling scenarios.

5 min read Updated July 2026

1. E-Commerce Product Scraping

ecommerce.py
python
1import crawlingo
2
3session = crawlingo.Session()
4dataset = crawlingo.Dataset("https://example.com/products/item-1", session)
5
6dataset.field("title", ".product-detail h1")
7dataset.field("price", ".product-detail .price", extract_type="price")
8dataset.field("sku", ".product-detail [data-sku]", extract_type="attr:data-sku")
9
10result = dataset.build()
11print(result.to_dict())

2. Pagination (3 Schemes)

Scheme A: NextLink (Following the Next Button Element)

python
1import crawlingo
2
3config = crawlingo.PaginationConfig.next_link("a.pagination-next")
4crawl = crawlingo.Crawl("https://example.com/blog", crawlingo.Session())
5crawl.with_pagination(config).field("title", "article h2")
6results = crawl.build()

Scheme B: PageNumber (Iterating numbered parameters)

python
1import crawlingo
2
3config = crawlingo.PaginationConfig.page_number("https://example.com/list?page={page}", start_page=1, max_pages=10)
4crawl = crawlingo.Crawl("https://example.com/list", crawlingo.Session())
5crawl.with_pagination(config).field("title", ".item-name")
6results = crawl.build()

3. Authenticated Fetching

auth_recipe.py
python
1import crawlingo
2
3session = crawlingo.Session()
4
5# 1. Bearer Token Auth
6session.bearer_auth("my_secret_token_123")
7
8# 2. HTTP Basic Auth
9session.basic_auth("user", "pass")
10
11# 3. Custom API Keys via Headers
12session.headers({"X-API-Key": "my-secret-key"})
13
14# 4. Session Cookies
15session.cookies({"session_token": "abcde12345"})

4. Change Detection & Webhooks

webhook_recipe.py
python
1import crawlingo
2
3session = crawlingo.Session()
4watcher = crawlingo.Watch("https://example.com/stock-ticker", session)
5
6watcher.field("price", ".ticker-value", extract_type="price")
7watcher.interval(10) # poll every 10 seconds
8
9def on_change(event):
10 print(f"Price updated from {event.old_value} to {event.new_value}!")
11
12watcher.on_change(on_change)