UNPKG

egypt-banks-scraper

Version:
51 lines (43 loc) 1.09 kB
/* eslint class-methods-use-this: ["error", { "exceptMethods": ["scraper"] }] */ import cheerio from 'cheerio'; import Bank from './Bank'; import { banksNames } from './banks_names'; export default class AIBK extends Bank { constructor() { const url = 'https://www.aibegypt.com/en/personal/'; const selector = '.table tbody tr'; super(banksNames.AIBK, url, selector); } /** * Scrape rates from html * @param {Object} html html of bank web page to scrape */ scraper(html) { const $ = cheerio.load(html); const tableRows = $('.table tbody tr'); const rates = []; tableRows.each((index, row) => { const currencyCode = $(row) .children() .eq(1) .text() .trim(); const buyRate = $(row) .children() .eq(2) .text() .trim(); const sellRate = $(row) .children() .eq(3) .text() .trim(); rates.push({ code: currencyCode, buy: Number(buyRate), sell: Number(sellRate), }); }); return rates; } }