Script Runner icon

Script Runner

Run custom scripts with jsdom or cheerio

Script Runner

AI-generated

Summary

Run a custom JavaScript script on each input item with access to the Cheerio and/or JSDOM HTML parsing libraries, using optional HTML input provided directly or from each item's JSON data.

Inputs

  • Library (required) — Select which HTML parsing library to use in the script: Cheerio, JSDOM, or both.
  • HTML Input — Provide HTML content as a string to parse within the script. If omitted, the node uses the 'html' property from the current item's JSON if available.
  • Custom Script (required) — Write custom JavaScript code that will be executed for each item. The script has access to cheerio, JSDOM, html (HTML content string), items (all input items array), $item (current item), and itemIndex.
  • Return Full Items (required) — Specify whether to merge the script output under a 'scriptOutput' key into each original item (true), or return only the script output transformed into a new item (false).

Output shape

a list of JSON items

Each output item corresponds to one input item. If 'Return Full Items' is true, the output item JSON merges the original input item's JSON with a 'scriptOutput' property containing the script return value. If false, output item JSON is the script return value itself (wrapped as {result: value} if the return is not an object). Errors produce an item containing an 'error' property if 'continueOnFail' is enabled.

Examples

Example 1: Extracting text from an HTML string using Cheerio

Set Library to 'Cheerio'. Provide HTML Input or ensure input items contain an 'html' property. Write a Custom Script accessing cheerio to parse HTML and extract data, then return it.

Example 2: Using JSDOM to manipulate DOM elements in HTML

Set Library to 'jsdom' or 'both'. Use the Custom Script to create a new JSDOM from the html string and query or modify DOM elements. Return desired data from the script.

Links

Discussion