mirror of
https://gitlab.silvrtree.co.uk/martind2000/recipes.git
synced 2025-02-10 10:49:17 +00:00
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
/**
|
|
* 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);
|
|
|
|
|
|
fs.writeFileSync(bodyfile, $.html());
|
|
fs.writeFileSync(htmlfile, tdihbody.html());
|
|
|
|
});
|
|
},
|
|
grabMarksDailyApple:function(url) {
|
|
logger.info(url);
|
|
var section = '#contentColumn';
|
|
request(url, function (err, resp, body) {
|
|
if (err)
|
|
throw err;
|
|
|
|
$ = cheerio.load(body);
|
|
var tdihbody = $(section);
|
|
var bodySec = tdihbody.find('div.post').first();
|
|
|
|
// fs.writeFileSync(bodyfile, $.html());
|
|
fs.writeFileSync(htmlfile, bodySec.html());
|
|
|
|
});
|
|
}
|
|
};
|
|
|
|
module.exports.grabMarksDailyApple('http://www.marksdailyapple.com/shakshuka-eggs-poached-in-spicy-tomato-sauce'); |