【问题标题】:Create new element in cheerio在cheerio中创建新元素
【发布时间】:2017-04-02 12:18:18
【问题描述】:

在cheerio 中创建新元素的最佳方式是什么?

可能是:

cheerio.load('<li>something in here!</li>')

$('li', '<li>bla, bla, bla, ...</li>')

【问题讨论】:

    标签: javascript jquery cheerio


    【解决方案1】:

    load 和上下文字符串都不会真正创建 HTML。它们是创建虚拟 DOM 的起点。

    Refer to the Manipulation section in the documentation 用于注入 DOM 的方法。即提供以下注入方法:

    • append
    • appendTo
    • prepend
    • prependTo
    • after
    • insertAfter
    • before
    • insertBefore
    • replaceWith
    • html
    • wrap

    【讨论】: