V
V
Vitaly the Wise2017-09-01 00:28:24
Node.js
Vitaly the Wise, 2017-09-01 00:28:24

How to log in to a site using Node.js?

Good afternoon. I want to parse the site, but for this you need to register first

const request = require('request');
const cheerio = require('cheerio');

request('https://url.com', (error, response, body) => {
    let $ = cheerio.load(body);
    const __RequestVerificationToken = $('#signin input').attr('name', '__RequestVerificationToken').val();

    const LoginUserName = '*****';
    const LoginPassword = '****';

    request.post(
        {
            url:'https://url.com/Login', 
            form: {
                '__RequestVerificationToken': __RequestVerificationToken, 
                LoginUserName, 
                LoginPassword 
        }
    },(err, httpResponse, body) => {

        if (err) {
            return console.error('Error:', err);
        }

        console.log('Body:', body);

    })
});

First, I go to the main page, take the key for authorization, and then pass the post request with the login and password. But in the answer it throws me to the error page. I tried to send them in Postman to body -> form-data and successfully authorized. help me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Shashenkov, 2017-09-01
@teknik2008

Headlines, look there.
And also jar (cookie) - most likely it is also necessary to skip

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question