Hello! I'm trying to go through authorization with phantomjs, but it doesn't work, here’s the code:

// Authentication "use strict"; var siteUrl = 'http://www.3dcontentcentral.com/secure/download-model.aspx? catalogid=10260&id=496588'; var page = require('webpage').create(); page.open(siteUrl, function (status) { if (status !== 'success') { console.log('Unable to access network'); } else { console.log("Status: " + status); page.render('yes.png'); var fs = require('fs'); fs.write('page.html', page.content, 'w'); //заполняем page.evaluate(function() { document.getElementById("3dcclogin").value = "mymail@mail.ru"; document.getElementById("3dccpassword").value = "mypass"; document.getElementById("btn_ucLogin").click(); }); } page.render('yes2.png'); fs.write('page1.html', page.content, 'w'); phantom.exit(); }); 

I changed the password and login. Can you please tell me what I am doing wrong?

  • what exactly is a mistake, what exactly is your "failure"? - tCode
  • I check the png-file after authorization, but there is only a popup-form in it, in theory the name should appear on the page. The same is true in the html-file, there is also a login button in the upper right corner, instead of it there should be a login name - ZaurK
  • one
    @ZaurK I think you need to start to pause for a second or two anyway before the second render, otherwise the screen just does not have time to change anything. - a-bobkov
  • Yes, it turned out, thanks - ZaurK

1 answer 1

 ///////всё работает без лишних слов////////// var page = require ('webpage').create(); var system = require("system"); page.open("адрес сайта", function(status){ console.log('открыто'); page.settings.resourceTimeout = 1000; page.onLoadFinished = function(status) { setTimeout(function() { page.render("ollgod.png"); console.log('see ollgod.png'); phantom.exit(); }, 10000) }; page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', function(){ page.evaluate(function (){ $("#ид или .класс").val("логин"); $("#ид или .класс").val("пароль"); $("#ид или .класс").click(); }); console.log('login good'); page.render("before_submit.png"); console.log('see login.png '); }); });