如何使用Grunt将HTML解析为DOM [英] How to parse HTML to DOM with Grunt

查看:163
本文介绍了如何使用Grunt将HTML解析为DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Grunt的新手,试图找到加载多个HTML文件并解析它们以提取一些值的方法。

I am new to Grunt, trying to find a way to load multiple HTML files and parse them to extract some values.

我尝试使用 jQuery.parseHTML HTMLParser 但都没有定义。有没有一种方法可以包含jQuery或可以解析HTML的lib?

I tried to use jQuery.parseHTML, HTMLParser but both are not defined. Is there a way to include jQuery or a lib that can parse HTML?

grunt.config.init({
    concat: {
        options: {
            dest: 'tmp',
            templates: ['public/*.html']
        }
    }
});

var recursiveConcat = function(source, result){
    grunt.file.expand(source).forEach(function(file){
        var data = grunt.file.read(file);
        // parse html to dom
        result += data;
    });
    return result;
};


推荐答案

Cheerio 是我喜欢使用的DOM解析器。我还没有尝试过,但 grunt-dom-massager 允许您加载在你的Gruntfile中加入Cheerio。

Cheerio is a DOM parser that I enjoy using. I haven't tried this, but grunt-dom-massager allows you to load Cheerio in your Gruntfile.

这篇关于如何使用Grunt将HTML解析为DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆