R
R
Ramil2015-08-07 22:24:30
Node.js
Ramil, 2015-08-07 22:24:30

What is the browser emulator on nodejs?

Hello. It took on one server of a friend to pick up data from the site. API no. You need to first log in to the site, then, in the logged in state, go to another page and collect the data. The server is protected from bots. Deletes js script in hidden input fields. If the fields are not removed and the form is submitted, then the server thinks it is a bot. So you need to execute js code.
Dug in the direction of phantomjs.

var url = 'http://test.ru/user/login',
    page = new WebPage();
    


page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';

page.open(url, function(status) {
    if (status !== 'success')
    {
      console.log('Unable to access network');
      phantom.exit();
      return;
    }
    else
    {
        page.viewportSize = {
            width: 1024,
            height: 1024
        };
        page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js", function() {
            page.onLoadFinished = function(){
                page.url = 'http://t118437.test.ru/admin/templates';
                
                var title = page.evaluate(function(){
                    return document.title;
                });
                
                setTimeout(function(){
                    console.log('test', title);
                    page.render("nextPage.png");    
                }, 5000)
                
                phantom.exit();
            };
            page.evaluate(function() {
                login = '[email protected]';
                pas = '123456';
                $('#user_mail').val(login);
                $('#user_pass').val(pas);

                $(".push-bottom").click();

            });
            
        });
    }
});

Here is the code that works. That is, the account is logged in and the script takes a screenshot of the account page. But I still need to go to another page after logging in. This is what I couldn't do. How to implement page navigation in phantomjs. The phantomjs documentation is very poor.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill, 2015-08-10
@kirill89

It is really difficult to deal with phantomjs because of the documentation, I can advise you to use a wrapper on nodejs - for example navit . It is intended primarily for testing purposes, but should work for you.

D
Dmitry Demin, 2015-08-08
@keksmen

I have not come across phantomjs, but I know that the task is easily solved with the help of electron 'a. It is well documented, but it is not a fact that it will work on a server where there is no graphical shell.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question