crawler

SQL-nativer Web-Crawler mit HTML-Extraktion und MERGE-Unterstützung

Maintainer: onnimonni

Installation und Laden

INSTALL crawler FROM community;
LOAD crawler;

Beispiel

SELECT url, jq(html.document, 'h1').text as title
FROM crawl(['https://example.com']);

Über crawler

Die crawler-Erweiterung stellt SQL-native Web-Crawling-Funktionen für DuckDB bereit.

Funktionen:

  • Tabellenfunktion crawl() mit automatischer Ratenbegrenzung und Einhaltung von robots.txt
  • crawl_url() für LATERAL-Joins
  • sitemap() zum Parsen von XML-Sitemaps
  • read_html() im Stil von Google-Sheets-IMPORTHTML (Tabellen, Listen, JS-Variablen)
  • Funktionen jq() und htmlpath() zur Extraktion über CSS-Selektoren
  • html.readability zur Artikel-Extraktion
  • html.schema zum Parsen von JSON-LD/Microdata
  • Syntax CRAWLING MERGE INTO für Upsert-Operationen

Beispiel mit read_html (wie Google Sheets =IMPORTHTML):

SELECT * FROM read_html('https://en.wikipedia.org/wiki/...', 'table.wikitable', 1);
SELECT * FROM read_html('https://example.com/page', 'js=jobs');

Beispiel mit Extraktion:

SELECT
url,
jq(html.document, '.price', 'data-amount') as price,
html.readability.title as article_title
FROM crawl(['https://example.com/products']);

Beispiel mit MERGE:

CRAWLING MERGE INTO pages
USING crawl(['https://example.com']) AS src
ON (src.url = pages.url)
WHEN MATCHED THEN UPDATE BY NAME
WHEN NOT MATCHED THEN INSERT BY NAME;

Vollständige Dokumentation: https://github.com/midwork-finds-jobs/duckdb-crawler

Hinzugefügte Funktionen

function_name function_type description comment examples
crawl table NULL NULL
crawl_stream table NULL NULL
crawl_url table NULL NULL
css_select scalar NULL NULL
discover scalar NULL NULL
htmlpath scalar NULL NULL
jq scalar NULL NULL
read_html table NULL NULL
sitemap table NULL NULL
stream_merge_internal table NULL NULL

Überladene Funktionen

Diese Erweiterung fügt keine Funktionsüberladungen hinzu.

Hinzugefügte Typen

Diese Erweiterung fügt keine Typen hinzu.

Hinzugefügte Einstellungen

name description input_type scope aliases
crawler_default_delay Default crawl delay in seconds if not in robots.txt DOUBLE GLOBAL []
crawler_max_response_bytes Maximum response body size in bytes (0 = unlimited) BIGINT GLOBAL []
crawler_respect_robots Whether to respect robots.txt directives BOOLEAN GLOBAL []
crawler_timeout_ms HTTP request timeout in milliseconds BIGINT GLOBAL []
crawler_user_agent User agent string for crawler HTTP requests VARCHAR GLOBAL []