-3

I want to find out if the document -which is an html file- has "some" tags. If so, I want to get all its attributes.

I tried

var data = require('test.html');
if(data.toLowerCase().indexOf('<iframe') > -1|| data.toLowerCase().indexOf('<iframe>') > -1){
 console.log('yeaaah it exist'); 

 // get iframe attributes
}

I was able to find if the tag exist, but how can I get its attributes? Also this is on server side.

Reporter
  • 3,897
  • 5
  • 33
  • 47
gabf Hahn
  • 117
  • 1
  • 3
  • 13

1 Answers1

0

Okay, I got it done using Cheerio

var cheerio = require("cheerio");
var url = "./test.html";  // if it does not work try with absolute url
download(url, function(data) {
if (data) {
// console.log(data);
var TestData = cheerio.load(data);
// to get the tag simply use TestData("sometag")
console.log(TestData("sometag").length);
 }
});
gabf Hahn
  • 117
  • 1
  • 3
  • 13