From 2bfae5b426bf4a0b99d3979ed12d63cb50c39b17 Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Thu, 19 Oct 2023 20:43:04 +0200 Subject: Add examples --- examples/coinmarketcap.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/coinmarketcap.js (limited to 'examples/coinmarketcap.js') diff --git a/examples/coinmarketcap.js b/examples/coinmarketcap.js new file mode 100644 index 0000000..7693fd8 --- /dev/null +++ b/examples/coinmarketcap.js @@ -0,0 +1,30 @@ +export const config = { + url: "https://coinmarketcap.com/", +}; + +export default function({ doc }) { + const rows = doc.find(".cmc-table tbody tr"); + + return { + currencies: rows + .map((row) => { + const cols = row.find("td"); + + return { + position: cols.get(1).text(), + currency: cols.get(2).find("p").get(0).text(), + symbol: cols.get(2).find("p").get(1).text(), + price: cols.get(3).text(), + change: { + "1h": cols.get(4).text(), + "24h": cols.get(5).text(), + "7dh": cols.get(6).text(), + }, + marketcap: cols.get(7).find("span").get(1).text(), + volume: cols.get(8).find("p").get(0).text(), + supply: cols.get(9).text(), + }; + }) + .slice(0, 10), + }; +} -- cgit v1.2.3