YTPTube can automatically scrape pages and enqueue new links using a generic task handler. This works by turning JSON definitions into site-specific scrapers.
Workflow
- Create a Definition: In the WebUI, go to
tasks > Definitions and create a JSON definition. - Create a Task: Create a task referencing the target URL. Ensure the task uses a preset with
--download-archive enabled to avoid duplicates. - Execution: The handler scans definitions, matches the task URL against
match_url (supports Glob and Regex), fetches the page, and extracts items.
Definition Schema
Each definition is a JSON object. Key fields include:
name: Identifier for logs.match_url: List of Glob or Regex strings to match task URLs.engine: The fetch engine (httpx default, or selenium for remote Chrome sessions).request: HTTP settings (method, url, headers, params, data, json_data, timeout).response: The response format (html default, or json).parse: Extraction logic.items: Container for per-item extraction. Requires a selector (CSS or XPath) and fields.fields: Mapping of keys to extraction rules. Each field requires a type (css, xpath, or jsonpath), an expression, and an attribute (e.g., text, html, href).
Parsing Rules
- Link Requirement: Every definition must provide a
link field (either at the top level or inside parse.items.fields). - Attributes:
text / inner_text: Applies normalize-space().html / outer_html: Returns raw HTML fragment.- For
link fields, if attribute is omitted, it defaults to href.
- JSON Responses: If
response.type is json, set type and field type to jsonpath and use JMESPath expressions.
Fetch Engines
- httpx: Default. Supports custom headers, params, JSON payloads, and proxies.
- selenium: Requires a remote Chrome session. Provide the hub URL in
engine.options.url. Supports arguments, wait_for (CSS/XPath), wait_timeout, and page_load_timeout.
{
"name": "example",
"match_url": ["https://example.com/articles/*"],
"engine": { "type": "httpx" },
"request": { "method": "GET", "url": "https://example.com/articles/latest" },
"response": { "type": "html" },
"parse": {
"items": {
"selector": ".columns .card",
"fields": {
"link": { "type": "css", "expression": ".card-header a", "attribute": "href" },
"title": { "type": "css", "expression": ".card-header a", "attribute": "text" }
}
}
}
}