【问题标题】:How to select text in html inside div who have same class with cheerio如何在div中选择与cheerio具有相同类的html中的文本
【发布时间】:2018-10-25 08:28:20
【问题描述】:

我希望从与cheerio 具有相同类(.hello) 的第二个div 中获取文本的html:

<div class="hello">blablabla</div>

<div class="hello"> 
<h2 id="coucou">Coucou</h2>
blablabla 2 html to <br> 
select this is the text I want<br>
blabla bla bla bal balbal blabla
</div>

我想要的结果:

blablabla 2 html to <br> 
select this is the text I want<br>
blabla bla bla bal balbal blabla

【问题讨论】:

    标签: javascript node.js cheerio


    【解决方案1】:

    看起来像你想要的:

    $('.hello + .hello').text()
    

    在 css 中,+ 表示下一个兄弟。

    【讨论】:

    • 但有时,我有三个同名的类,我必须使用 h2 id coucou 获取文本
    • 也许$('h2#coucou').parent()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 2022-07-27
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多