Problem with javascriptEnabled on Phantomjs

I used phantoms to clear some data from a website. To speed up the download, I disabled js execution on the webpage by doing the following:

page.settings.javascriptEnabled = false;

but this causes a problem - it returns page.evaluate(somefunc.toString())return nullno matter what the function should return. If I keep the default js value true, it page.evaluate()will work again.

How do I get around this? Thanks

+5
source share
1 answer

In general, do not do this.

However, if you really need it, you can enable JavaScript, but block the download of external .js files. For instance:.

page.onResourceRequested = function(requestData, request) {
  if (requestData['Content-Type'] == 'application/javascript' || requestData['Content-Type'] == 'text/javascript') {
    console.log('Disabling JavaScript files. Aborting: ' + requestData['url']);
    request.abort();
  }
};
+3
source

All Articles