Puppeteer is a Node.js library that provides a high-level API for controlling headless or full browsers like Google Chrome or Chromium. It enables web automation, scraping, testing, and performance monitoring. With Puppeteer, you can simulate user actions, extract data, and generate PDFs or screenshots.
You can find out more about it on their official page here.
Setup
Before anything, check if Node.js is installed: Open a terminal (Command Prompt or shell) and type the following command:
node -v
If you get a version number, Node.js is already installed. The version number will look like this:
In this case go to Step 2: Create a project directory
If Node.js is not installed on your system you will get this error:
'node' is not recognized as an internal or external command
If this is your case continue with the steps below:
Step 1: Install Node.js
Download Node.js:
Go to the Node.js official website.
Download the LTS version for your operating system
2. Install Node.js:
Run the installer you downloaded.
Follow the installation wizard.
Step 2: Create a project directory
Open a terminal and create a directory for your project:
mkdir puppeteer-nodemaven-proxy
2. Go to directory:
cd puppeteer-nodemaven-proxy
3. Initialize the project:
npm init -y
NOTE:
This will create a package.json
file in your project directory.
Step 3: Install Puppeteer
Install Puppeteer with:
npm install puppeteer
Step 4: Set Up Puppeteer with a NodeMaven Proxy
Create a new file,
index.js
, in your project directory. Use your preferred text editor.Add the following code to
index.js
:
For Username and password authentication:
const puppeteer = require('puppeteer');
(async () => {
// Launch Puppeteer with a proxy
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--proxy-server=http://gate.nodemaven.com:8080'
],
});
const page = await browser.newPage();
// Authenticate with the proxy
await page.authenticate({
username: 'REPLACE THIS WITH YOUR NODEMAVEN PROXY USERNAME',
password: 'REPLACE THIS WITH YOUR NODEMAVEN PROXY PASSWORD'
});
try {
// Navigate to a website
await page.goto('https://nodemaven.com/');
console.log('Page title:', await page.title());
} catch (err) {
console.error('Error navigating to the page:', err);
} finally {
// Close the browser
await browser.close();
}
})();
For Whitelisted IP authentication:
const puppeteer = require('puppeteer');
(async () => {
// Launch Puppeteer in headless mode with a proxy
const browser = await puppeteer.launch({
headless: true, // Default is true, so no visible browser
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--proxy-server=http://gate.nodemaven.com:8405' // Replace with your IP whitelisting proxy
],
});
const page = await browser.newPage();
try {
// Navigate to the website
await page.goto('https://nodemaven.com/');
// Get the page title
const title = await page.title();
console.log('Page title:', title);
} catch (err) {
console.error('Error navigating to the page:', err);
} finally {
// Close the browser
await browser.close();
}
})();
Step 5: Run the Script
Use the following command in the terminal:
node index.js
Expected Output: If everything is set up correctly, the script should log the title of the page (https://nodemaven.com
) to the console.
Now you are ready to personalize your script and start using Puppeteer with NodeMaven proxies!