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>
Use $.html("body") instead of $("body").html().