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