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

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

  • $.merge().

    Returns

    arr1, with elements of arr2 inserted.

    Alias

    Cheerio.merge

    See

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

    Type Parameters

    • T

    Parameters

    • arr1: WritableArrayLike<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