javascript - Handle the response of a submit from within evaluate() -
i'm using phantomjs scrape page , running problem. here's basic user steps it's executing;
- load login page (using page.open)
- enter credentials (using page.evaluate within callback passed open)
- submit form (also in page.evaluate)
when user steps in browser post request made submitting form comes couple set-cookies in headers, these cookies necessary subsequent requests. when phantomjs executes these actions cookies fail set proven by;
page.open(loginurl, function (status) { if (status === 'success') { //evaluate account , pwd login page.evaluate(function (email, password) { console.log("email: " + email); console.log("pass: " + password); document.queryselector('input[name="theaccountname"]').value = email; document.queryselector('input[name="theaccountpw"]').value = password; document.queryselector('form').submit(); return; }, email, password); } (var = 0; < page.cookies.length; i++) console.log(json.stringify(page.cookies[i]) + "\n");
the above code print 6 of 8 cookies necessary, 2 it's missing ones returned submit i'm doing evaluate. there anyway access response? why cookies returned not being set? bug in phantomjs? seems if workflow requires submission of form doesn't correctly emulate browser (the response ignored/i have not access it).
phantomjs works other browser. cookies should set.
form submission requires @ least round trip set cookies, form.submit()
doesn't wait request answered. returns immediately. when access page.cookies
isn't updated.
use settimeout()
wait little before looping on page.cookies
.
the webkit engine behind phantomjs 1.x more 4 years old. possible request dropped because of bugs or incompatibilities. might need update phantomjs 2.
to see whether there problems register onconsolemessage
, onerror
, onresourceerror
, onresourcetimeout
events.
Comments
Post a Comment