UNPKG

ipbcrawler

Version:

Package to mine forum data using the Invision Power Board platform.

140 lines (125 loc) 3.05 kB
const { accessElementInformation, sendElementToAccessInformation } = require('./../utils/extractor-access-element-information') const he = require('he') const clear = require('./../utils/clear')(["\n", "\t"]) const accessSubCategoryInformation = accessElementInformation((element) => { return { title: he.decode(clear(element.find('a').text())) } }) /** * [description] * @param {[type]} (element [description] * @return {[type]} [description] */ const accessCategoryInformation = accessElementInformation((element, $) => { /** * [main description] * @type {[type]} */ const main = $(element.find('.ipsDataItem_main')) return { /** * [icon description] * @type {[type]} */ icon: element.find('.ipsDataItem_icon img').attr('src'), /** * [title description] * @type {[type]} */ title: he.decode(clear(main.find('.ipsDataItem_title a').text())), /** * [description description] * @type {[type]} */ description: he.decode(clear(main.find('.ipsDataItem_meta').text())), /** * [subCategories description] * @type {[type]} */ subCategories: sendElementToAccessInformation({ /** * [elements description] * @type {[type]} */ elements: main.find('.ipsDataItem_subList li'), /** * [extractor description] * @type {[type]} */ extractor: accessSubCategoryInformation($) }) } }) const accessRankInformation = accessElementInformation((element) => { /** * Element rank element * @type {[type]} */ const domElement = element.find('a') /** * */ return { name: he.decode(domElement.text()), withHTML: he.decode(domElement.html()) } }) /** * [description] * @param {[type]} (element [description] * @return {[type]} [description] */ const accessZoneInformation = accessElementInformation((element, $) => { return { /** * [title description] * @type {[type]} */ title: he.decode(element.find('h2.cForumTitle a').text()), /** * [categories description] * @type {[type]} */ categories: sendElementToAccessInformation({ /** * [elements description] * @type {[type]} */ elements: element.find('ol li.ipsDataItem'), /** * [extractor description] * @type {[type]} */ extractor: accessCategoryInformation($) }) } }) module.exports = ($) => { return { zones: sendElementToAccessInformation({ elements: $('.cForumRow.ipsBox'), extractor: accessZoneInformation($) }), /** * [ranks description] * @type {[type]} */ ranks: sendElementToAccessInformation({ /** * [elements description] * @type {[type]} */ elements: $( $('.cWidgetContainer .ipsWidget_inner.ipsPad') .find('.ipsList_inline') .not('.ipsList_csv') ).find('li'), /** * [extractor description] * @type {[type]} */ extractor: accessRankInformation($) }) } }