2017-02-14 5 views
1

Cheerioでは、現在のノードのテキストだけをどのように取得しますか?現在のノードのテキストのみを取得する

var cheerio = require('cheerio') 

const htmlString = '<div>hello<span>world</span></div>' 

$ = cheerio.load(htmlString, { ignoreWhitespace: true }) 

console.log($('div').text()) //helloworld 
console.log($('span').text()) //world 

どのようにあなただけのhelloを得るのですか?

答えて

0

あなたはこれを行うことができます。

console.log($('div').contents().first().text()) # hello 
+0

は、参考のためにhttps://github.com/cheeriojs/cheerio/issues/146を参照してください。 – Kevin

関連する問題