Options
All
  • Public
  • Public/Protected
  • All
Menu

cheerio

Index

References

Re-exports html
Re-exports text
Re-exports xml

DOM Node Type Aliases

AnyNode: ParentNode | ChildNode

Re-exporting all of the node types.

ParentNode: Document | Element | CDATA

Re-exporting all of the node types.

Other Type Aliases

AcceptedElems<T>: BasicAcceptedElems<T> | ((this: T, i: number, el: T) => BasicAcceptedElems<T>)

Elements that can be passed to manipulation methods, including functions.

Type Parameters

AcceptedFilters<T>: string | FilterFunction<T> | T | Cheerio<T>

Supported filter types, for traversal methods.

Type Parameters

  • T

BasicAcceptedElems<T>: Cheerio<T> | T[] | T | string

Elements that can be passed to manipulation methods.

Type Parameters

FilterFunction<T>: ((this: T, i: number, el: T) => boolean)

Type Parameters

  • T

Type declaration

    • (this: T, i: number, el: T): boolean
    • Function signature, for traversal methods.

      Parameters

      • this: T
      • i: number
      • el: T

      Returns boolean

SelectorType: `${SelectorSpecial}${AlphaNumeric}${string}` | `${AlphaNumeric}${string}`

Type for identifying selectors. Allows us to "upgrade" queries using selectors to return Elements.

Variables

default: CheerioAPI

The default cheerio instance.

deprecated

Use the function returned by load instead.

Functions

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

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