Answer the question
In order to leave comments, you need to log in
How can I use nightmare to execute a script before the .end() operation?
The .then() call is only executed after .end(). There is an evaluate method borrowed from PhantomJS, which executes a script with browser variables; variables with a value can be passed there, but for some reason they are not passed with the function (undefined). Task: execute the server script, passing the value from the browser, and continue the execution in the same way.
***
And in addition I offer an amusing problem.
I'm trying to log in to vk.com using nightmare, but the password field does not receive focus and does not accept key events. In the markup, you can see that keyup is installed on it. If you try to overwrite it to null, then nothing will come of it, although the function is visible in the property when debugging.
What kind of protection is this, where can you learn about the principles of its operation and how can you bypass it?
nightmare
.goto('http://vk.com')
.type('#quick_login', vk.login)
.type('#quick_pass', vk.pass)
.click('#quick_login_button')
.wait(() => {
return document.title.search(/Диалоги/) != -1;
})
.evaluate(() => {
alert('It`s cool!!!');
})
.end()
.then(()=> {
console.log('complete!');
});
Answer the question
In order to leave comments, you need to log in
direct use of nightmare is not very convenient, it is more comfortable to work with it inside the generator
in your case, there may be a problem of blocking the input field by a contact, you can try something like .wait(400).type('#quick_login',vk.login).wait( 400).type('#quick_pass', vk.pass)...
And I also see at least incorrect id input of the vk, index_email, index_pass blocks, respectively.
In general, you can have a nightmare like this:
function * run() {
let html = yield nightmare.goto(href);
let resultEvaluate = yield nightmare.evaluate(()=>{return document.body;});
yield nightmare.end();
nightmare
.goto('https://vk.com')
.type('#index_email', vk.login)
.type('#index_pass', vk.pass)
.click('#index_login_button')
.wait(() => {
return document.title.search(/Диалоги/) != -1;
})
.evaluate(() => {
return 'its cool!!!';
})
.end()
.then((result)=> {
console.log(result); // its cool!!!
})
.catch(console.error); // будете пренебрегать обработкой ошибок и кошмар будет именно ваш , а не сайта для парсинга....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question