Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface CheerioAPI

Hierarchy

  • StaticType
    • CheerioAPI

Callable

  • This selector method is the starting point for traversing and manipulating the document. Like jQuery, it's the primary method for selecting elements in the document.

    selector searches within the context scope which searches within the root scope.

    example
    $('.apple', '#fruits').text();
    //=> Apple

    $('ul .pear').attr('class');
    //=> pear

    $('li[class=orange]').html();
    //=> Orange

    Type parameters

    Parameters

    Returns Cheerio<S extends SelectorType ? Element : T>

Index

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

    • Create a querying function, bound to a document created from the provided markup.

      Note that similar to web browser contexts, this operation may introduce <html>, <head>, and <body> elements; set isDocument to false to switch to fragment mode and disable this.

      see

      https://cheerio.js.org#loading for additional usage information.

      Parameters

      • content: string | AnyNode | AnyNode[] | Buffer

        Markup to be loaded.

      • Optional options: null | CheerioOptions

        Options for the created instance.

      • isDocument: boolean = true

        Allows parser to be switched to fragment mode.

      Returns CheerioAPI

      The loaded document.

Methods

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

    alias

    Cheerio.contains

    see

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

    Parameters

    • container: AnyNode

      Potential parent node.

    • contained: AnyNode

      Potential child node.

    Returns boolean

    Indicates if the nodes contain one another.

  • merge<T>(arr1: WritableArrayLike<T>, arr2: ArrayLike<T>): ArrayLike<T> | undefined
  • $.merge().

    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

    arr1, with elements of arr2 inserted.

  • parseHTML(this: CheerioAPI, data: string, context?: unknown, keepScripts?: boolean): AnyNode[]
  • parseHTML(this: CheerioAPI, data?: null | ""): null
  • 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.

    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[]

    The parsed DOM.

  • 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>
    alias

    Cheerio.root

    Parameters

    Returns Cheerio<Document>

    Cheerio instance wrapping the root node.

  • 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.

    Parameters

    Returns string

    The rendered document.