D
D
Dvorak2016-05-30 21:57:51
JavaScript
Dvorak, 2016-05-30 21:57:51

How to implement this in Node.js?

There is a specific site. Let's say transport.surge.sh There, when you click on the "Example" button, a file is downloaded.
How can I write a Node.js script that every minute would go to this site through a SPECIFIC browser and download this file?
Which way to dig? What modules/frameworks/libraries to use? I just don't even know which way to go.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Eugene 222, 2016-05-30
@mik222

Node.js has integration with Phantom.js (which is a headless browser as you ask)

var phantom = require('phantom');

var sitepage = null;
var phInstance = null;
phantom.create()
    .then(instance => {
        phInstance = instance;
        return instance.createPage();
    })
    .then(page => {
        sitepage = page;
        return page.open('https://stackoverflow.com/');
    })
    .then(status => {
        console.log(status);
        return sitepage.property('content');
    })
    .then(content => {
        console.log(content);
        sitepage.close();
        phInstance.exit();
    })
    .catch(error => {
        console.log(error);
        phInstance.exit();
    });

H
hiwibu, 2016-05-30
@hiwibu

setInterval + each time you change the request headers

D
Dark Hole, 2016-05-30
@abyrkov

Through the browser Node.js cannot. Just download - maybe.
But why?

D
Dronbas, 2016-06-01
@Dronbas

https://github.com/request/request#custom-http-headers
This is an example of custom header substitution in the request module.
Wrap the whole thing in setInterval and process saving to a file in callback like this:
https://nodejs.org/api/fs.html#fs_fs_writefile_fil...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question