如何从nodejs中的网站中提取标签和属性?

How to extracting tags and attributes from a website in nodejs?

我想提取元标记并检查 'viewport' 是否存在于 nodejs 的元标记中。我搜索并找不到任何有效的方法。有什么建议吗?

也许这会有所帮助:

function getMeta(){
    var  el = document.getElementsByTagName('head'),        
     ch =  el[0].children;

    for (let e=0; e<ch.length; e++) {           
        if ( ch[e].tagName.toLowerCase() === 'meta' && ch[e].getAttribute('name') === "viewport"){
            console.log(ch[e]);
        }
    }
}

然后调用函数为

getMeta();