V
V
Vyacheslav Grachunov2017-03-05 13:17:24
Parsing
Vyacheslav Grachunov, 2017-03-05 13:17:24

How to start a headless browser through a specific network interface?

Actually, you need to parse a complex site. So I decided to use a headless browser. phantom.js Actually, all this needs to be managed from Node.js, so there is also Casper.js + Spooky.js
But you need to parse from different network interfaces (tunX - OpenVPN)
When there was just a request, there was a localAddress parameter, in which the ip address of the interface and all.
But how to make walk not directly Phantom.js? Well, or Firefox via Slimer.js (Casper.js supports it)
Actually, here is an example from the site. Works. But how to specify the network interface here?

var Spooky = require('spooky');

var spooky = new Spooky({
        child: {
            transport: 'http'
        },
        casper: {
            logLevel: 'debug',
            verbose: true
        }
    }, function (err) {
        if (err) {
            e = new Error('Failed to initialize SpookyJS');
            e.details = err;
            throw e;
        }

        spooky.start(
            'http://en.wikipedia.org/wiki/Spooky_the_Tuff_Little_Ghost');
        spooky.then(function () {
            this.emit('hello', 'Hello, from ' + this.evaluate(function () {
                return document.title;
            }));
        });
        spooky.run();
    });

spooky.on('error', function (e, stack) {
    console.error(e);

    if (stack) {
        console.log(stack);
    }
});

/*
// Uncomment this block to see all of the things Casper has to say.
// There are a lot.
// He has opinions.
spooky.on('console', function (line) {
    console.log(line);
});
*/

spooky.on('hello', function (greeting) {
    console.log(greeting);
});

spooky.on('log', function (log) {
    if (log.space === 'remote') {
        console.log(log.message.replace(/ \- .*/, ''));
    }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2017-03-05
@Qwentor

proxy + already direct the proxy where necessary

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question