0
我只想访问h1的文本(在这种情况下为H1 title is here
),但它会打印所有内容。我试图在text()
之前加.remove('.small-title')
,但它不起作用。使用Cheerio访问包含其他元素的类的文本
<div class="modal-know>
<h1>
H1 title is here
<div class="small-title">
<a href="title-a">Click</a>
<a href="title-b">Click 2</a>
</div>
</h1>
</div>
Node.js的代码
var newsTitle = $2('.modal-know h1').text(); // prints out everything
console.log(newsTitle);