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.

Revisions

  1. KevCui created this gist Apr 13, 2020.
    23 changes: 23 additions & 0 deletions 1to50.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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);
    })();