Giter Site home page Giter Site logo

oxylabs / puppeteer-proxy-integration-js Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 2.0 20 KB

A tutorial for implementing Oxylabs` Residential and Datacenter proxies with Puppeteer using JavaScript

JavaScript 100.00%
puppeteer javascript headless proxy residential-proxy proxy-list-github github-proxy-list proxy-list socks5-proxy-list nodejs

puppeteer-proxy-integration-js's Introduction

Oxylabs' Proxy Integration with Puppeteer

Oxylabs promo code

Requirements

Puppeteer

npm install puppeteer

Integrating Datacenter Proxies

Getting a List of Proxies

Open the following URL in the browser and enter your credentials. You will see a list of proxies in plain text:

https://proxy.oxylabs.io/all

Using Proxies

If you wish to select any of the provided proxies, save the proxy IP, along with the port in a variable.

To use all these proxies, first, save these proxies as an array in your code:

let proxies = [
    '127.0.0.1:60000',
    '127.0.0.2:60000',
    '127.0.0.3:60000',
    '127.0.0.4:60000'
  ]

To select one of these proxies randomly, use the following line of code:

var proxy = proxies[Math.floor(Math.random() * proxies.length)];

The proxy server you will use needs to be supplied as --proxy-server argument.

Create a variable that can contain all the arguments in an array.

Additionally, launchOptions can also contain other information, such as headless mode as following:

const launchOptions = {
  // Set the proxy server to the server variable
  args: ['--proxy-server=' + proxy],

  // Set additional launch options here
  headless: false
};

After creating the launchOptions variable, create a puppeteer instance and launch the browser.

const browser = await puppeteer.launch(launchOptions);

Finally, to authenticate using your credentials, call the page.authenticate function after creating a page.

// Create a new page
const page = await browser.newPage();

// Set the username and password provided by Oxylabs
await page.authenticate({
  username: 'USERNAME',
  password: 'PASSWORD'
});

For the complete code sample, see this file.

Integrating Residential Proxies

Random Proxy Using the Proxy API

To get a random proxy, use the proxy server pr.oxylabs.io:7777.

As mentioned above, the proxy server you will use needs to be supplied as --proxy-server argument.

Create a variable that can contain all the arguments in an array.

Additionally, launchOptions can also contain other information, such as headless mode as following:

const launchOptions = {
  // Set the proxy server to the server variable
  args: ['--proxy-server=pr.oxylabs.io:7777']
};

After creating the launchOptions variable, create a puppeteer instance and launch the browser.

const browser = await puppeteer.launch(launchOptions);

Finally, to authenticate using your credentials, call the page.authenticate function after creating a page.

// Create a new page
const page = await browser.newPage();

// Set the username and password provided by Oxylabs
await page.authenticate({
  username: 'USERNAME',
  password: 'PASSWORD'
});

For the complete code sample, see this file.

Country Specific Proxies

If you wish to use country-specific proxies, all you need to do is change the proxy server.

For example, if you want to use a proxy for the United States, you can use the following code:

const launchOptions = {
  args: ['--proxy-server=us-pr.oxylabs.io:10001']
};

In this example, us-pr.oxylabs.io:10000 is the country specific entry point for the United States.

Another example is gb-pr.oxylabs.io:20000, which is the country specific entry point for the United Kingdom.

For a complete list of all entry points, see Country Specific Entry Nodes

puppeteer-proxy-integration-js's People

Contributors

augustoxy avatar oxyjohan avatar oxyjowyd avatar oxylabsorg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.