phantomjs icon indicating copy to clipboard operation
phantomjs copied to clipboard

concurrent page loads are not possible?

Open ijx33 opened this issue 13 years ago • 22 comments

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.

ijx33 avatar Jun 16 '13 01:06 ijx33

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.

ijx33 avatar Jun 16 '13 03:06 ijx33

Could it be the RFC-mandated limit on number of parallel requests per hostname?

richardjharris avatar Jun 28 '13 14:06 richardjharris

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.

ijx33 avatar Jun 28 '13 15:06 ijx33

+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.

sebayaki avatar Feb 06 '14 12:02 sebayaki

+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...

msk86 avatar Mar 03 '14 10:03 msk86

+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

lab101 avatar Jan 04 '15 12:01 lab101

I found it is possible that keep watching </body> via page.evaluate.

At least it can return full html text to you.

msk86 avatar Jan 05 '15 01:01 msk86

+1 I am having the same problem with version 1.9.15.

Any idea if this is fixed on 2.x?

JonnyBGod avatar Feb 23 '15 21:02 JonnyBGod

+1 1.9.8

Xychun avatar Jun 12 '15 06:06 Xychun

Is this bug actual on phantomJS2?

byaka avatar Dec 06 '15 21:12 byaka

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

azev avatar Aug 13 '16 16:08 azev

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

vitallium avatar Aug 13 '16 16:08 vitallium

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.

azev avatar Aug 13 '16 16:08 azev

What PhantomJS version are you using? 2.1.1 works for me (Windows)

vitallium avatar Aug 13 '16 17:08 vitallium

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.

azev avatar Aug 13 '16 17:08 azev

Please attach the sample script which reproduces your problem.

vitallium avatar Aug 13 '16 17:08 vitallium

    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);
    });

azev avatar Aug 13 '16 17:08 azev

Are you running them on the same URL?

vitallium avatar Aug 13 '16 18:08 vitallium

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)

azev avatar Aug 13 '16 18:08 azev

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)

azev avatar Aug 13 '16 18:08 azev