Automatically adding <html><head><body> ?
See original GitHub issueOSX 10.12.4 Node 8.0 “cheerio”: “1.0.0-rc.1”
Not sure if this is expected, but:
let $ = cheerio.load('<div>Hello</div>');
console.log($.html());
// <html><head></head><body><div>Hello</div></body></html>
While in my case the auto-wrapping as an <html>
document is weirdly useful, I was still surprised to see it. Is this a bug, or a feature? I don’t see a .fragment()
method or anything like that. Maybe just missed something.
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:42
- Comments:33 (14 by maintainers)
Top Results From Across the Web
don't automatically adding <html><head><body> #1247
basically if you load document as fragment - elements like html, body and head will not be added. All reactions.
Read more >Don't put html, head and body tags automatically, beautifulsoup
Unlike html5lib, this parser makes no attempt to create a well-formed HTML document by adding a <body> tag. Unlike lxml, it doesn't even ......
Read more >HTML head Elements - W3Schools
The <head> element is a container for metadata (data about data) and is placed between the <html> tag and the <body> tag. HTML...
Read more >It tells me that my "</head> tag needs to come before your ...
The HTML-Element has no parent but is a parent to 2 child-Element's the 'head'-Element and the 'body'-Element. The 'head'- and 'body'-Element, both being ......
Read more >HTML Body Tag: Master The Most Important HTML Element ...
The <body> element contains the entire content of a webpage. It must be the second element inside of the parent <html> element, following...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Use
xmlMode: true
to avoid auto-wrapping:To give an answer here: The
load
method has a third argument,isDocument
. If you set this tofalse
, your document will be parsed in fragment mode and no<html>
root tag (or other boilerplate) will be inserted. To use the example from the original issue: