Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
How to query cheerio for html output inclusive of the selector tags

If you use $("body").html() cheerio returns the html inside the body tags. How can I query cheerio for the body content inclusive of the opening and closing body tags?

Take for example a file like this:

<body class="body">
 <div>
  <h1>Foo Bar</h1>
 </div>
</body>

<style>
.body {
 margin: 0;
}
</style>

The following code will output the html contents of body. The output will not include the <body> tags, which is what I want to achieve

const cheerio = require("cheerio");
const $ = cheerio.load(text);
const body = $("body").html();

console.log(body);
// <div>
//  <h1>Foo Bar</h1>
// </div>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use $.html("body") instead of $("body").html().

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda