UNPKG

scrape-it

Version:
71 lines (68 loc) 2.08 kB
"use strict"; const scrapeIt = require("../lib"); scrapeIt("http://ionicabizau.net", [ // Fetch the articles on the page (list) { listItem: ".article" , name: "articles" , data: { createdAt: { selector: ".date" , convert: x => new Date(x) } , title: "a.article-title" , tags: { selector: ".tags" , convert: x => x.split("|").map(c => c.trim()).slice(1) } , content: { selector: ".article-content" , how: "html" } } } , { listItem: "li.page" , name: "pages" , data: { title: "a" , url: { selector: "a" , attr: "href" } } } // Fetch some additional data , { title: ".header h1" , desc: ".header h2" , avatar: { selector: ".header img" , attr: "src" } } ], (err, page) => { console.log(err || page); }); // { articles: // [ { createdAt: Mon Mar 14 2016 00:00:00 GMT+0200 (EET), // title: 'Pi Day, Raspberry Pi and Command Line', // tags: [Object], // content: '<p>Everyone knows (or should know)...a" alt=""></p>\n' }, // { createdAt: Thu Feb 18 2016 00:00:00 GMT+0200 (EET), // title: 'How I ported Memory Blocks to modern web', // tags: [Object], // content: '<p>Playing computer games is a lot of fun. ...' }, // { createdAt: Mon Nov 02 2015 00:00:00 GMT+0200 (EET), // title: 'How to convert JSON to Markdown using json2md', // tags: [Object], // content: '<p>I love and ...' } ], // pages: // [ { title: 'Blog', url: '/' }, // { title: 'About', url: '/about' }, // { title: 'FAQ', url: '/faq' }, // { title: 'Training', url: '/training' }, // { title: 'Contact', url: '/contact' } ], // title: 'Ionică Bizău', // desc: 'Web Developer, Linux geek and Musician', // avatar: '/images/logo.png' }