recipes/server/grab.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-02-22 17:05:13 +00:00
/**
* Created by Martin on 22/02/2016.
*/
var http = require('http'), request = require('request'), cheerio = require('cheerio'), util = require('util');
var jsonfile = require('jsonfile'), fs = require('fs'), STRING = require('string');
var log4js = require('log4js');
var logger = log4js.getLogger();
var bodyfile = __dirname + '/' + 'body.html';
var htmlfile = __dirname + '/' + 'testoutput.html';
module.exports = {
grab:function(url,section) {
logger.info(url);
request(url, function (err, resp, body) {
if (err)
throw err;
$ = cheerio.load(body);
var tdihbody = $(section);
2016-02-22 17:11:46 +00:00
2016-02-22 17:05:13 +00:00
fs.writeFileSync(bodyfile, $.html());
fs.writeFileSync(htmlfile, tdihbody.html());
});
},
2016-02-22 17:11:46 +00:00
grabMarksDailyApple:function(url) {
2016-02-22 17:05:13 +00:00
logger.info(url);
var section = '#contentColumn';
request(url, function (err, resp, body) {
if (err)
throw err;
$ = cheerio.load(body);
var tdihbody = $(section);
2016-02-22 17:11:46 +00:00
var bodySec = tdihbody.find('div.post').first();
2016-02-22 17:05:13 +00:00
2016-02-22 17:11:46 +00:00
// fs.writeFileSync(bodyfile, $.html());
fs.writeFileSync(htmlfile, bodySec.html());
2016-02-22 17:05:13 +00:00
});
}
};
module.exports.grabMarksDailyApple('http://www.marksdailyapple.com/shakshuka-eggs-poached-in-spicy-tomato-sauce');