You can run Puppeteer in Jupyter notebook by using a JavaScript kernel instead of the default Python one. There is the famous IJavaScript kernel but that does not work with Puppeteer. The reason is that Puppeteer is async and needs a kernel that supports that. You can instead use this patched version of the IJavaScript kernel that adds this async support.
Assuming that you already have jupyter
installed, you can install the
patched IJavaScript
kernel using npm:
$ npm install -g ijavascript-await
And then you need to install puppeteer in the same directory where your notebooks will be stored. You can do so using this command:
$ npm install puppeteer
Once both IJavaScript and Puppeteer are installed, you can run the Jupyter notebook using the convenience function provided by IJavaScript:
$ ijsnotebook
This will open up the web interface. Once there, you can create a new JavaScript-based notebook:
Then you can import and use puppeteer as you normally would and everything should work just fine:
let puppeteer = require('puppeteer');
let browser = await puppeteer.launch({headless: false})