I have a few html files on my harddrive that I'd like to use jquery on to extract data from. Is this possible to do using cheerio? I've tried giving cheerio the local path but it doesn't work. One idea I had would be to create a web server in node, read from the html file, and then pipe it to cheerio through the server - would this
Using Clean architecture for Node. For sending larger code, we definitely require to have a separate file for html code. Response object gives a sendFile() function to return a html file to client. How to provide path to html file in sendFile() ? We import the path core module of node.
Use res. sendFile instead of reading the file manually so express can handle setting the content-type properly for you. You don't need the app. engine line, as that is handled internally by express.
The input is an html string, so you need to read the html content yourself:
var fs = require('fs'); cheerio.load(fs.readFileSync('path/to/file.html'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With