Created
          April 13, 2020 12:24 
        
      - 
      
- 
        Save KevCui/ad3f962c31128d6211cde7e0c34f5d71 to your computer and use it in GitHub Desktop. 
    Complete 1to50 challenge with puppeteer https://twitter.com/fltoledo/status/1248789014632476672
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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); | |
| })(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Average score ~2s