Created
September 16, 2016 22:56
-
-
Save alana314/0bbbb4e018bc17b0c35853c3ccbd0013 to your computer and use it in GitHub Desktop.
Use node.js and jquery (cheerio) to recursively search files for external links
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var cheerio = require('cheerio') | |
var recursive = require('recursive-readdir'); | |
var fs = require('fs'); | |
recursive('.', function (err, files) { | |
// Files is an array of filename | |
for(f = 0; f < files.length; f++) | |
{ | |
if(files[f].indexOf('.php') != -1) | |
{ | |
var data = fs.readFileSync(files[f]).toString(); | |
var $ = cheerio.load(data); | |
var links = $('a'); | |
if(links.length) | |
{ | |
console.log("===" + files[f]); | |
for(i = 0; i < links.length; i++) | |
{ | |
if(typeof(links[i].attribs.href) != 'undefined' && links[i].attribs.href.indexOf('http') != -1) | |
{ | |
console.log(links[i].attribs.href); | |
} | |
} | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment