Can I load a local html file with the cheerio package in node.js?

后端 未结 3 2010
再見小時候
再見小時候 2020-12-28 14:19

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 pa

3条回答
  •  误落风尘
    2020-12-28 14:34

    Extending damphat's answer to make it work for relative paths:

    import fs from 'fs';
    import path from 'path';
    
    const filePath = path.join(__dirname, './path/to/file.html');
    const $ = cheerio.load(fs.readFileSync(filePath));
    
    

提交回复
热议问题