Skip to content

Instantly share code, notes, and snippets.

@KevCui
Created April 13, 2020 12:24
Show Gist options
  • Save KevCui/ad3f962c31128d6211cde7e0c34f5d71 to your computer and use it in GitHub Desktop.
Save KevCui/ad3f962c31128d6211cde7e0c34f5d71 to your computer and use it in GitHub Desktop.
Complete 1to50 challenge with puppeteer https://twitter.com/fltoledo/status/1248789014632476672
const puppeteer = require('puppeteer-core');
(async() => {
const cPath = '/usr/bin/chromium';
const isHeadless = true;
const url = 'http://zzzscore.com/1to50/en';
const browser = await puppeteer.launch({executablePath: cPath, headless: isHeadless});
const page = await browser.newPage();
await page.goto(url, {timeout: 30000, waitUntil: 'domcontentloaded'});
await page.waitForSelector('.box');
for (var i = 1; i <= 50; i++) {
var selector="//div[text() = '" + i + "']";
await page.waitFor(selector);
var el = await page.$x(selector);
await el[0].click();
}
await page.waitForSelector('.resultContent');
const score = await page.evaluate(() => document.querySelector('.level').innerHTML);
await browser.close();
console.log(score);
})();
@KevCui
Copy link
Author

KevCui commented Apr 13, 2020

node 1to50.js

Average score ~2s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment