【问题标题】:Strip out content from File in Local Directory using Node JS使用 Node JS 从本地目录中的文件中删除内容
【发布时间】:2016-04-17 15:26:16
【问题描述】:

目前,我在一个文件夹 (70,000) 中有 html 文件,其中包含我想要提取的静态内容。内容位于 ID 为“内容”的 div 中。我想我可以让 nodeJS 遍历每个文件,获取文件名及其内容。我想出了第一部分,关于如何让 nodejs 打开文件并获取位于特定 div (id="content") 中的内容的任何建议。

如果这有什么影响的话,我目前正在运行一台 Windows 机器......

【问题讨论】:

    标签: html node.js


    【解决方案1】:

    你可以使用cheerio

    var cheerio = require('cheerio'),
    $ = cheerio.load(file_content);
    
    // use it like jQuery
    var div_content = $('#content').text();
    

    【讨论】:

      猜你喜欢
      • 2018-12-04
      • 2014-05-07
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-24
      相关资源
      最近更新 更多