Search code examples
htmlnode.jsviewportmeta-tags

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


I wanted to extract the metatag and check whether 'viewport' is present in the meta tag in nodejs. I searched and couldn't find any efficient method. Any suggestions?


Solution

  • Maybe this would be helpful:

    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]);
            }
        }
    }
    

    and just call function as

    getMeta();