NodeJS X-Ray Hide IP Address

3.9k Views Asked by At

Is it possible to change your IP Address and User Agent when using NodeJS/X-Ray to make requests to an external site?

1

There are 1 best solutions below

4
On

Yes you can.

But instead of passing the url(s) you want to scrape to x-ray, rather use the request module to get the response, and pass that to x-ray. This will allow you to pass options into the request module, which will allow you to change your User Agent as well as use a proxy (which is the best way to 'change' your IP).

var options = {
    headers: {'User-Agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 7.0; InfoPath.3; .NET CLR 3.1.40767; Trident/6.0; en-IN)'},
    proxy: 'http://us-ny.proxymesh.com:31280',
    strictSSL: false
};

request(url, options, function (err, response) {

    xray(response.body, {
        //x-ray selectors            
    })
    (function (err, obj) {
    //parse results
    }
});