Interface CheerioAPI

Hierarchy

  • StaticType
    • CheerioAPI

Properties

_options: InternalOptions

The options the document was originally loaded with.

_root: Document

The root the document was originally loaded with.

fn: Cheerio<any>

Mimic jQuery's prototype alias for plugin authors.

load: ((content: string | AnyNode | AnyNode[] | Buffer, options?: null | CheerioOptions, isDocument?: boolean) => CheerioAPI)

Type declaration

    • (content: string | AnyNode | AnyNode[] | Buffer, options?: null | CheerioOptions, isDocument?: boolean): CheerioAPI
    • The .load static method defined on the "loaded" Cheerio factory function is deprecated. Users are encouraged to instead use the load function exported by the Cheerio module.

      Deprecated

      Use the load function exported by the Cheerio module.

      Example

      const $ = cheerio.load('<h1>Hello, <span>world</span>.</h1>');
      

      Parameters

      Returns CheerioAPI

Methods

  • Checks to see if the contained DOM element is a descendant of the container DOM element.

    Returns

    Indicates if the nodes contain one another.

    Alias

    Cheerio.contains

    See

    https://api.jquery.com/jQuery.contains/

    Parameters

    • container: AnyNode

      Potential parent node.

    • contained: AnyNode

      Potential child node.

    Returns boolean

  • Extract multiple values from a document, and store them in an object.

    Returns

    An object containing the extracted values.

    Type Parameters

    • M extends ExtractMap

    Parameters

    • this: CheerioAPI
    • map: M

      An object containing key-value pairs. The keys are the names of the properties to be created on the object, and the values are the selectors to be used to extract the values.

    Returns ExtractedMap<M>

  • $.merge().

    Returns

    arr1, with elements of arr2 inserted.

    Alias

    Cheerio.merge

    See

    https://api.jquery.com/jQuery.merge/

    Type Parameters

    • T

    Parameters

    • arr1: Writable<ArrayLike<T>>

      First array.

    • arr2: ArrayLike<T>

      Second array.

    Returns ArrayLike<T> | undefined

  • Parses a string into an array of DOM nodes. The context argument has no meaning for Cheerio, but it is maintained for API compatibility with jQuery.

    Returns

    The parsed DOM.

    Alias

    Cheerio.parseHTML

    See

    https://api.jquery.com/jQuery.parseHTML/

    Parameters

    • this: CheerioAPI
    • data: string

      Markup that will be parsed.

    • Optional context: unknown

      Will be ignored. If it is a boolean it will be used as the value of keepScripts.

    • Optional keepScripts: boolean

      If false all scripts will be removed.

    Returns AnyNode[]

  • Parameters

    Returns null

  • Sometimes you need to work with the top-level root element. To query it, you can use $.root().

    Example

    $.root().append('<ul id="vegetables"></ul>').html();
    //=> <ul id="fruits">...</ul><ul id="vegetables"></ul>

    Returns

    Cheerio instance wrapping the root node.

    Alias

    Cheerio.root

    Parameters

    Returns Cheerio<Document>

  • Render the document as text.

    This returns the textContent of the passed elements. The result will include the contents of script and stype elements. To avoid this, use .prop('innerText') instead.

    Returns

    The rendered document.

    Parameters

    Returns string