concurrent page loads are not possible?
Attempting to have more than 1 require("webpage")create() objects doesn't seem to work - eg trying something like
pageload (require("webpage")create(), "http://url1")
and
pageload (require("webpage")create(), "http://url2")
when pageload is a function of general type:
pageload (page, url){
page.open(url, function (){
//do some page.evaluate stuff ...
});
I've tried fully closing over the pageload functions so that they should definately be separate instances including separate page instances.
What I appear to get is one of the pages returning null or empty (but the page.onLoadFinished reports "success").
I didn't find any documentation about this - it's possible that I am still doing something wrong -or is this not supported (yet?).
Ask if full examples are needed.
ok - probably my mistake - concurrent access seems to work on 'most' websites - there may be some minor issue - below is an example I found.
function makepage(x) {
'use strict';
var y = require("webpage").create();
return function () {
y.open(x, function (status) {
console.log("status", status);
var text = y.evaluate(function () {
return document.body.innerText;
//return document.title; // issue with getting innerText/innerHTML - document.title appears to work in the examples that fail
});
console.log("text", text);
});
};
}
makepage('http://www.britainfromabove.org.uk/asearch?gazetteer=City%20of%20Kingston%20upon%20Hull&ADMIN_AREA=City%20of%20Kingston%20upon%20Hull&view=list&order=4&page=0')();
makepage('http://www.britainfromabove.org.uk/asearch?gazetteer=East%20Riding%20of%20Yorkshire&ADMIN_AREA=East%20Riding%20of%20Yorkshire&view=list&order=4&page=0')();
//THE REST BELOW WORK
//makepage('http://phantomjs.org/')();
//makepage('http://nodejs.org/')();
//makepage('https://www.google.co.uk/search?client=opera&q=nodejs&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggest')();
//makepage('http://www.bing.com/search?q=nodejs&qs=n&form=QBLH&filt=all&pq=nodejs&sc=8-6&sp=-1&sk=')();
//makepage('http://en.wikipedia.org/wiki/Nodejs')();
//makepage('http://blog.nodejs.org/')();
//makepage('http://www.britainfromabove.org.uk/asearch?search=hull')();
//makepage('http://www.britainfromabove.org.uk/asearch?search=goole')();
Most sites work fine - the two given that don't work generate non fatal errors on parsing - each url works fine when not attempted concurrently.
Probably not phantomjs's fault but will leave here in case enlightening.
Could it be the RFC-mandated limit on number of parallel requests per hostname?
The bottom two requests (commented out) to www.britainfromabove.org.uk (same site) worked (last time I checked) - whe tried concurrently .. if the problemn host connection limit I'd expect it to fail here too.
I also checked a asynchronous GET request using plain node.js on the problematic urls - got status 200, with the full bodies returned. I assume this would send similarly timed requests to the server.
It looks like the isssue might be with phantomjs - though it's an obscure case.
+1 Have the same issue with @ijx33. When I try open multiple URLs concurrently, status returns 'success' and document.title is set, but body is null. Strange thing is when I try 5 concurrent open, randomly 1-2 bodies return correctly and others null.
+1 Same issue here with phantomjs v 1.9.7
When I open 2 urls concurrently, the status of the first one always returns 'success', no body but part of head tag...
+1 same issue here 1.9.8 on osx Loading two pages from localhost only one get loaded correctly. The multiurl sample does work https://github.com/ariya/phantomjs/blob/master/examples/render_multi_url.js probably because its more synchronously
I found it is possible that keep watching </body> via page.evaluate.
At least it can return full html text to you.
+1 I am having the same problem with version 1.9.15.
Any idea if this is fixed on 2.x?
+1 1.9.8
Is this bug actual on phantomJS2?
I'm also having the same issue! this is definetly a bug:
var page1 = require('webpage').create();
page1.open('http://...', function(status) {
var ret1 = page1.evaluate(function() {
return document.body.outerHTML;
});
});
var page2 = require('webpage').create();
page2.open('http://...', function(status) {
var ret2 = page2.evaluate(function() {
return document.body.outerHTML;
});
});
page1: document will be always null
It works with PhantomJS 2: This is my test script:
var webpage = require('webpage');
var page1 = webpage.create();
page1.open('http://google.com', function(status) {
var ret1 = page1.evaluate(function() {
return document.title;
});
console.log('WEBPAGE 1: ' + ret1);
});
var page2 = webpage.create();
page2.open('http://bing.com', function(status) {
var ret2 = page2.evaluate(function() {
return document.title;
});
console.log('WEBPAGE 2: ' + ret2);
});
And the output:
> phantomjs.exe test.js
WEBPAGE 1: Google
WEBPAGE 2: Bing
document.title works. but try this:
document.querySelectorAll('div.tab-detail li a[href*="/important/"]')[5].textContent;
It only works if page1 OR page2 is running but NOT IF both are running
If I comment page2 block then page1 works the desired result (return). Otherwise it returns null.
What PhantomJS version are you using? 2.1.1 works for me (Windows)
my version is 2.1.1.
As I wrote:
document.title works. but try this:
document.querySelectorAll('div.tab-detail li a[href*="/important/"]')[5].textContent;
It only works if page1 OR page2 is running but NOT IF both are running
If I comment page2 block then page1 works the desired result (return). Otherwise it returns null.
Please attach the sample script which reproduces your problem.
var page1 = webpage.create();
page1.open('http://.../', function(status) {
var ret1 = page1.evaluate(function() {
//return document.title;
return document.querySelectorAll('div.tab-detail li a[href*="/asdasd/"]')[1].textContent;
});
console.log('WEBPAGE 1: ' + ret1);
});
var page2 = webpage.create();
page2.open('http://..../', function(status) {
var ret2 = page2.evaluate(function() {
//return document.title;
return document.querySelectorAll('div.tab-detail li a[href*="/xsdf/"]')[5].textContent;
});
console.log('WEBPAGE 2: ' + ret2);
});
Are you running them on the same URL?
either way... same url or different. Now this is interesting...
the code above returns:
WEBPAGE 1: null
WEBPAGE 2: (my result2 ok)
and if i call it twice in the same run-time , it works both only the 2nd time.
WEBPAGE 1: null
WEBPAGE 2: (my result2 ok)
WEBPAGE 1: (my result1 ok)
WEBPAGE 2: (my result2 ok)
and for 3 pages concurrently:
WEBPAGE 1: null
WEBPAGE 2: null
WEBPAGE 3: (my result3 ok)
WEBPAGE 1: (my result1 ok)
WEBPAGE 2: (my result2 ok)
WEBPAGE 3: (my result3 ok)