Due to memory caching, --disk-cache=false
will not help. As discussed here and here, this feature is not available yet and will be a part of phantomJS 2. What you can do is download current dev (more info here) and build it on your side as the feature is already there.
PhantomJS: onResourceRequested won't fire for second page.open() on same domain
-
13-07-2023 - |
Pregunta
I have two page.open calls that run in succession. As resources are requested, I output the url of the given resource to the console.
var page = require('webpage').create();
var resourceCounter = 0;
page.onResourceRequested = function (resource) {
console.log(resourceCounter++ + '.\t', resource.url);
};
page.open('http://phantomjs.org');
setTimeout(function () {
resourceCounter = 0;
page.open('http://phantomjs.org/documentation');
}, 5000);
setTimeout(function(){
phantom.exit();
}, 10000);
If I attempt to open two URLs on different domains, everything works as expected--I see a full list of the pages' requested resources. However, if I request the same page twice, or two pages from the same domain (as in the example above), rather than seeing the page's requested resources listed out twice, I see this:
Resource requests for: http://phantomjs.org/
0 http://phantomjs.org/
1 http://phantomjs.org/
2 http://phantomjs.org/
3 http://fonts.googleapis.com/css?family=Droid+Sans:400,700
4 http://phantomjs.org/css/main.css
5 http://www.google-analytics.com/ga.js
6 https://s3.amazonaws.com/github/ribbons/forkme_left_white_ffffff.png
7 http://phantomjs.org/img/phantomjs-logo.png
8 http://phantomjs.org/img/icon-release.png
9 http://phantomjs.org/img/icon-ml.png
10 http://phantomjs.org/img/icon-bugs.png
11 http://www.google-analytics.com/__utm.gif?utmwv=5.5.0&utms=1&utmn=1675561797&utmhn=phantomjs.org&utmcs=UTF-8&utmsr=2560x1440&utmvp=400x300&utmsc=32-bit&utmul=en-us&utmje=0&utmfl=-&utmdt=PhantomJS%20%7C%20PhantomJS&utmhid=1661770756&utmr=-&utmp=%2F&utmht=1398973179893&utmac=UA-21665893-1&utmcc=__utma%3D205055825.123505717.1398973180.1398973180.1398973180.1%3B%2B__utmz%3D205055825.1398973180.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&utmu=q~
Resource requests for: http://phantomjs.org/documentation/
0 http://phantomjs.org/documentation/
1 http://www.google-analytics.com/__utm.gif?utmwv=5.5.0&utms=2&utmn=1424746795&utmhn=phantomjs.org&utmcs=UTF-8&utmsr=2560x1440&utmvp=400x300&utmsc=32-bit&utmul=en-us&utmje=0&utmfl=-&utmdt=Documentation%20%7C%20PhantomJS&utmhid=873610113&utmr=-&utmp=%2Fdocumentation%2F&utmht=1398973180268&utmac=UA-21665893-1&utmcc=__utma%3D205055825.123505717.1398973180.1398973180.1398973180.1%3B%2B__utmz%3D205055825.1398973180.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&utmu=q~
In other words, the results captured via page.onResourceRequested
for the second page.open() call are truncated.
Note: I am seeing this behavior with the cache disabled.
Any help would be much appreciated!
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow