【发布时间】:2021-04-26 18:25:51
【问题描述】:
我很久以前就解决了这个问题,但我现在忘记了。 当我的主要选择器是时,我如何访问该日期
$('.date')
let cheerio = require('cheerio')
let html = `
<html>
<body>
<span class="date">
<span class="category">Article</span>
Sat, 22 Jan 2021 11:12
</span>
</body>
</html>`
let $ = cheerio.load(html)
// Empty
console.log($('.date').next().text())
// Empty
console.log($($('.date').children()[0]).next().next().text())
// Empty
console.log($($('.date').children()[0]).next().text())
// Empty
$('.date').each(el => { console.log($(el).text())})
【问题讨论】:
-
这行得通吗?
$('.date').contents().last().text() -
哇,我不记得我以前使用过内容,是的!它的工作和添加 .trim() 因为这么多空间谢谢
标签: node.js jquery-selectors cheerio