Last active
September 6, 2018 12:52
-
-
Save sorenlouv/491b9377e3f540ba58ff630de0e829df to your computer and use it in GitHub Desktop.
Randomly click around a webpage
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
// Deprecated. Use puppeteer instead: https://gist.github.com/sqren/94ab2b9c5e88c1c119182425b19bcd59 | |
const { Chromeless } = require('chromeless'); | |
const initialUrl = process.env.CHROMELESS_URL || 'https://www.dr.dk'; | |
const chromeless = new Chromeless({ | |
launchChrome: true | |
}); | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
function goToUrl(url) { | |
return chromeless.goto(url).evaluate(() => { | |
const links = document.querySelectorAll('a[href^="/"]'); | |
const link = links[Math.floor(Math.random() * links.length)]; | |
return link.href; | |
}); | |
} | |
async function run(url) { | |
console.log(`Opening ${url}`); | |
const nextUrl = await goToUrl(url); | |
await sleep(6000 + Math.floor(Math.random() * 10000)); | |
return run(nextUrl); | |
} | |
run(initialUrl).catch(e => console.error(e)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment