Actor

jaroslavhejlek/uncollectable-site

  • Builds
  • latest 0.0.12 / 2018-06-07
  • Created 2018-06-04
  • Last modified 2018-06-07
  • grade 1

Description

Solution to collect the uncollectable site


API

To run the actor, send a HTTP POST request to:

https://api.apify.com/v2/acts/jaroslavhejlek~uncollectable-site/runs?token=<YOUR_API_TOKEN>

The POST payload will be passed as input for the actor. For more information, read the docs.


Example input

Content type: application/json; charset=utf-8

{ "url": "https://uncollectable.site" }

Source code

Based on the apify/actor-node-chrome Docker image (see docs).

const Apify = require('apify');


const numCPUs = require('os').cpus().length;

console.log(numCPUs);

const solution1 = async (INPUT, browser) => {
    const page = await browser.newPage();
    let solution = '';
    page.on('response', async (response) => {
       if (response.url().includes('actions/textme.php')) {
           solution = await response.text();
       }
    });
    
    await page.goto(INPUT.url, { waitUntil: 'domcontentloaded', timeout: 60000 });
    
    const key = await page.evaluate(() => document.querySelector('h1 span').innerText);
    const { keyboard } = page;
    
    const keys = {
        enter: 'Enter',
        spacebar: 'Space',
        period: 'Period',
        equals: 'Equal',
        'delete': 'Delete',
    };
    let keyboardKey = keys[key];
    
    if (!keyboardKey) throw new Error(`Unknow key ${key}, site probably changed.`);
    console.log('Key to press', keyboardKey);
    while(!solution) {
        await keyboard.down(keyboardKey);
        await keyboard.down(keyboardKey);
        await new Promise(resolve => setTimeout(resolve, 500));
        await keyboard.up(keyboardKey);
    };
    console.log('1:', solution);
    await page.close();
}

const solution2 = async (INPUT, browser) => {
    const page = await browser.newPage();
    let solution = '';
    page.on('response', async (response) => {
       if (response.url().includes('actions/textme.php')) {
           solution = await response.text();
       }
    });
    
    await page.goto(INPUT.url, { waitUntil: 'domcontentloaded', timeout: 60000 });
    
    await page.evaluate(() => {
        $.ajax({
            url: "../../actions/textme.php",
    		type: "post",
    		data: {"action": "textme"},
    		dataType: "text",
    		success: function(data) {},
          	error: function(xhr){}	
    	});
    });
    
    while(!solution) {
        await new Promise(resolve => setTimeout(resolve, 500));
    };
    console.log('2:', solution);
    await page.close();
}

Apify.main(async () => {
    try {
        const INPUT = await Apify.getValue('INPUT');
        const browser = await Apify.launchPuppeteer();
        await solution1(INPUT, browser);
        await solution2(INPUT, browser);
        await browser.close();
    } catch (err) {
        console.error(err);
        process.exit(1);
    }
});