B
B
BestJS2018-09-16 23:05:51
JavaScript
BestJS, 2018-09-16 23:05:51

phantom js. How to log in to VK?

In general, I want to parse some information from VK.
I can not get authorization :) I
enter the correct password, login too.
But VK doesn’t like something and throws out an error: Screenshot
And if you go through authorization from the main page of VK, then after submitting the form it redirects to an empty browser page about:blank
Please help

let phantomPrebuilt = require('phantomjs-prebuilt');
let driver = require('promise-phantom');

driver.create({
  path: phantomPrebuilt.path
})
.then(phantom =>
  phantom.createPage()
  .then(page => page)
)
.then(page => {
  let url = "https://vk.com/login";
  page.settings = {
    loadImages: true,
    javascriptEnabled: true,
    userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
  };
  return page.open(url)
    .then(() => page.render("1.png"))
    .then(() => page.evaluate(function(a) {
      d = document;
      d.getElementById("email").value = "+telefon";
      d.getElementById("pass").value = "password";
      d.getElementById("login_button").click();
    }))
    .then(() => page.render("2.png"))
    .then(() => setTimeout(() => page.render("3.png"), 5000))
})
.catch((error) => console.log(error));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
qq1, 2018-10-19
@qq1

The settings for the page must be passed through the .set method:

let phantomPrebuilt = require('phantomjs-prebuilt')
let driver = require('promise-phantom')

driver.create({
  path: phantomPrebuilt.path
})
.then(phantom =>
  phantom.createPage()
  .then(page => page)
)
.then(page => {
  let url = 'https://vk.com/login'
  // создаем объект настроек
  let settings = {
    loadImages: true,
    javascriptEnabled: true,
    userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
  }
  // передаем через .set
  return page.set('settings', settings)
    .then(() => page.open(url))
    .then(() => page.render('1.png'))
    .then(() => page.evaluate(function (a) {
      d = document
      d.getElementById('email').value = ''
      d.getElementById('pass').value = ''
      d.getElementById('login_button').click()
    }))
    .then(() => page.render('2.png'))
    .then(() => setTimeout(() => page.render('3.png'), 5000))
})
.catch((error) => console.log(error))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question