alexscheelmeyer / node-phantom

bridge to PhantomJS from Node.js
317 stars 117 forks source link

Infinite loop when scraping page #47

Closed futurechan closed 11 years ago

futurechan commented 11 years ago

I am using the sample code for scraping this url: http://www.anthropologie.com/anthro/category/office+d%e9cor+%26+stationery/home-office.jsp

The code goes into an infinite loop of creating a phantom instance, calling createPage(), and then calling page.open(). The function I call to create the phantom instance does not get recalled.

The only two npm packages I'm using are the phantomjs and node-phantom packages.

Here's the code:

var phantom=require('node-phantom');

var getPage = function(url, callback) { phantom.create(function(err,ph) { console.log('phantom created.'); if(err){ ph.exit(); callback(err); }else{ ph.createPage(function(err,page) { console.log('page created.');

            if(err){
                ph.exit();
                callback(err);
            }else{
                page.open(url, function(err) {
                    console.log('page opened: ' + url);

                    ph.exit();
                });
            }
        });
    }
}, {

phantomPath: require('phantomjs').path, parameters: {'ignore-ssl-errors':'yes'}
}); }

getPage('http://www.anthropologie.com/anthro/category/office+d%e9cor+%26+stationery/home-office.jsp', function(err){ console.log('done'); })

alexscheelmeyer commented 11 years ago

Have not been able to reproduce this. I tried your code with one difference : did not use phantomjs package as I already have PhantomJs installed. So removed the phantomPath key. My output:

phantom created.
page created.
page opened: http://www.anthropologie.com/anthro/category/office+d%e9cor+%26+stationery/home-office.jsp

and then it exited. Is that not what should happen? I have just today updated the npm package. You could try the newest version.