Skip to content

Instantly share code, notes, and snippets.

@DavidMellul
Created March 27, 2018 16:56
Show Gist options
  • Select an option

  • Save DavidMellul/05a3625d95bd268eda6c9c8514fe397e to your computer and use it in GitHub Desktop.

Select an option

Save DavidMellul/05a3625d95bd268eda6c9c8514fe397e to your computer and use it in GitHub Desktop.
// Dependencies and stuff, who cares ?
// ES6 way
(async () => {
// Browser launched
const browser = await puppeteer.launch();
// New tab created
const tab = await browser.newPage();
// Navigate to a website
await tab.goto('http://www.website.fr/');
// Click somewhere
await tab.click('#somewhereCSSSelector');
// Type something somewhere
await tab.type('#somewhereCSSSelector', 'something');
})();
// For some of you who might be unfamiliar with the syntax
// (function(){})() creates an anonymous function and runs it, just like that.
// In ES6, the above code is translated into ( () => {} )()
// Making use of async/await statements to make the code look sequential without callback hell, we get =>
// ( async() => {} )()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment