0

I've searched all over the web for a solution with no luck so far. I know this is a documented issue, but I am only trying to load a single web page and all the responses have been "this happens trying to do tests on 200 pages".

I have tried:

page.settings.loadImages = true; page.settings.loadplugins = false;

I added the ``page.close()` even though like I said, it's only with one URL right now.

I've tried setting loadImages to false as well. It works fine when I remove my one line of JavaScript (for example replacing it with document.title but as soon as that line is there, the memory usage rockets to 1000MB and then it quits.

My only goal is to check if a certain element exists on the page. How can I resolve this issue? None of the solutions I've found online are working for me.

The code in question:

var system = require('system');
var page = require('webpage').create();
page.settings.userAgent = 'Chrome/52.0.2743.116';
var url = 'http://www.example.com/';
var ending = system.args[1];
ending = encodeURIComponent(ending);
url = url + ending;

page.settings.loadImages = false;
page.settings.loadplugins = false;

page.viewportSize = { width: 1680, height: 1050 };

page.open(url, function(status) {
setTimeout(function(){
  var elem = page.evaluate(function() {
    return $(".primary-info")[0];
  });
  if(!elem){
    console.log('no image found');
    page.render(ending+'.png');
      }
    page.close();
    phantom.exit();
      }, 5000);
});

1 Answer 1

1

Don't just return the whole object, there could be quite a lot of its attributes. Only take what is necessary:

  var elem = page.evaluate(function() {
    var data = {};
    var item = $(".primary-info")[0];
    data.title = item.value;
    data.color = item.style.color;
    return data;
  });
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you soooo much! I think it works now! Oh you saved me so much manual work... I had no idea that it was trying to return so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.