Created
January 10, 2016 14:42
-
-
Save loujaybee/fb0cb9825c0d81121bb9 to your computer and use it in GitHub Desktop.
Extracting html in node
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
var Promise = require('bluebird'); | |
var fs = Promise.promisifyAll(require('fs')); | |
var runRegex = function(html) { | |
var extract_test_data = /(status_)(passed|failed)(.{16})([a-z]+)([0-9]+)(.{2})([0-9]{3})/gm; | |
var output = {}; | |
while ((result = extract_test_data.exec(html)) != null) { | |
output[result[7]] = result[2]; | |
} | |
return output | |
}; | |
var logToConsole = function(result){ | |
console.log(JSON.stringify(result)); | |
}; | |
var parseHtmlForStatusReport = (function() { | |
return fs.readFileAsync('./example.html', 'utf-8') | |
.then(runRegex) | |
.then(logToConsole) | |
.then(process.exit); | |
})(); | |
/* | |
Result: | |
{ | |
"155": "failed", | |
"003": "passed", | |
"019": "failed", | |
"022": "failed", | |
"025": "failed" | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment