UNPKG

egypt-banks-scraper

Version:
52 lines (44 loc) 1.18 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 AUDI extends Bank { constructor() { const url = 'http://www.bankaudi.com.eg/egypt/fx-rates'; const selector = '.ratesTable tbody tr'; super(banksNames.AUDI, url, selector); } /** * Scrape rates from html * @param {Object} html html of bank web page to scrape */ scraper(html) { const $ = cheerio.load(html); const tableRows = $('.ratesTable tbody tr'); const rates = []; tableRows.each((index, row) => { const currencyCode = $(row) .children() .eq(0) .text() .trim(); const buyRate = $(row) .children() .eq(3) .text() .trim(); const sellRate = $(row) .children() .eq(4) .text() .trim(); if (Number(buyRate) === 0 || Number(sellRate) === 0) return; rates.push({ code: currencyCode, buy: Number(buyRate), sell: Number(sellRate), }); }); return rates; } }