Skip to main content

NodeJs Request-Promise Fake Headers Integration

The following are two examples of how to integrate the Fake Browser Headers API and the Fake User-Agent API into your NodeJs Request-Promise based web scrapers.


NodeJs Request-Promise Fake Browser Headers API Integration

To integrate the Fake Browser Headers API you should configure your scraper to retrieve a batch of the most up-to-date headers when the scraper starts and then configure your scraper to pick a random header from this list for each request.

Here is an example NodeJs Request-Promise scraper integration:


import request from 'request-promise';

const scrapeopsAPIKey = 'YOUR_API_KEY';

(async () => {

try{

// Get Headers List
const sopsOptions = {
method: 'GET',
url: `http://headers.scrapeops.io/v1/browser-headers?api_key=${scrapeopsAPIKey}`,
}

const sopsResponse = await request(sopsOptions)
const jsonResponse = JSON.parse(sopsResponse)
const headersList = jsonResponse['result']

// Use Random Header Set In Request
const options = {
method: 'GET',
url: 'http://httpbin.org/headers',
headers: headersList[Math.floor(Math.random()*headersList.length)]
}


const response = await request(options)
console.log(response);

} catch (error){
console.log('error', error)
}


})();


NodeJs Request-Promise Fake User-Agent API Integration

To integrate the Fake User-Agent API you should configure your scraper to retrieve a batch of the most up-to-date user-agents when the scraper starts and then configure your scraper to pick a random user-agent from this list for each request.

Here is an example Request-Promise scraper integration:


import request from 'request-promise';

const scrapeopsAPIKey = 'YOUR_API_KEY';

(async () => {

try{

// Get User-Agent List
const sopsOptions = {
method: 'GET',
url: `http://headers.scrapeops.io/v1/user-agents?api_key=${scrapeopsAPIKey}`,
}

const sopsResponse = await request(sopsOptions)
const jsonResponse = JSON.parse(sopsResponse)
const userAgentList = jsonResponse['result']

// Use Random User-Agent In Request
const options = {
method: 'GET',
url: 'http://httpbin.org/headers',
headers: {
'User-Agent': userAgentList[Math.floor(Math.random()*userAgentList.length)],
}
}


const response = await request(options)
console.log(response);

} catch (error){
console.log('error', error)
}


})();

Here the scraper will use a random user-agent for each request.


API Parameters

The following is a list of API parameters that you can include with your requests to customise the header list response.

ParameterDescription
api_keyThis is a required parameter. You can get your Free API key here.
num_resultsBy default the API returns a list of 10 user-agents, however, you can increase that number by changing the num_results number. Max is 100 headers.