Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
loads a page and checks for non secure items.
var request = require('request');
var cheerio = require('cheerio');
var url = require('url');
var httpsurl = 'https://www.yahoo.com/';
var assets = {
img: {src:'src'},
link: {src:'href'},
script: {src:'src'}
};
request(httpsurl, function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
Object.keys(assets).forEach(function(element) {
var attrtolook = assets[element].src;
$(element).each(function(i, link){
var parsedurl, elementurl = $(link).attr(attrtolook);
if(elementurl !== undefined){
parsedurl = url.parse(elementurl);
if(parsedurl.host !== null && parsedurl.protocol !== 'https:'){
console.log(element + ' points to ' + elementurl );
}
}
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.