Created
November 23, 2021 21:28
-
-
Save kami4ka/75529366667cef069b57f4fd5dceff76 to your computer and use it in GitHub Desktop.
Scrape new tokens from Dextools using ScrapingAnt API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get data from new DexTools token listings | |
* | |
* ScrapingAnt allows you to scrape for free using proxy servers | |
* | |
* npm install @scrapingant/scrapingant-client | |
* npm install cheerio | |
**/ | |
const cheerio = require('cheerio'); | |
const ScrapingAnt = require('@scrapingant/scrapingant-client'); | |
const API_KEY = '<SCRAPINGANT_API_KEY>'; | |
const TOKENS_URL = 'https://www.dextools.io/app/ether/pool-explorer'; | |
const BASE_URL = 'https://www.dextools.io'; | |
const client = new ScrapingAnt({ apiKey: API_KEY }); | |
main() | |
.then(console.log) | |
.catch(console.error); | |
async function main() { | |
// Get all visible tokens | |
const tokens = []; | |
const tokensResponse = await client.scrape(TOKENS_URL, { wait_for_selector: '.datatable-header' }); | |
const $ = cheerio.load(tokensResponse.content) | |
const rows = $('.datatable-row-center'); | |
rows.each((i, el) => { | |
const columns = $(el).find('datatable-body-cell').toArray(); | |
if (i !== 0) { | |
tokens.push({ | |
url: BASE_URL + $(columns[0]).find('a').attr('href'), | |
symbol: $(columns[0]).text(), | |
timestamp: $(columns[2]).text(), | |
price: $(columns[5]).text(), | |
liquidity: $(columns[6]).text(), | |
poolAmount: $(columns[7]).text(), | |
poolVariation: $(columns[8]).text(), | |
poolRemaining: $(columns[9]).text(), | |
}); | |
} | |
}); | |
return tokens; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment