Phantomjs works but is very slow

谁说胖子不能爱 提交于 2019-12-02 19:18:42
Layke

Yes this is normal. When you attempt to render, PhantonJS will still wait for the page.open event to fire the load event to signify that the entire DOM has been loaded.

Take a look at what happens when I load espn.com locally on my system. It takes ~2 seconds for DOMContentLoaded to finish, and then ~7 seconds for the ready event to fire.

Devaroop

Well, in my case, the page was waiting for some GET requests and was not able to reach the requests' server and it kept waiting for long. I could only figure it out when i used the remote debugger option.

phantomjs --remote-debugger-port=9000 loadspeed.js <some_url>

and inside the loadspeed.js file

page.onResourceRequested = function (req) {
    console.log('requested: ' + JSON.stringify(req, undefined, 4));
};

page.onResourceReceived = function (res) {
    console.log('received: ' + JSON.stringify(res, undefined, 4));
};

and then loading localhost:9000 in any webkit browser (safari/chrome) and seeing the console logs where i could figure out it was waiting for some unreachable requests for a long time.

TO BYPASS THIS - REDUCE THE TIMEOUT:

page.settings.resourceTimeout = 3000; //in milliseconds

and things were very quick after that. Hope this helps

I didn't thought that the following would work but for me it did (on Windows):

open Internet Explorer > Internet Options > Connections > LAN Settings and disable the "Automatically detect settings"

original Post: https://plus.google.com/+MatthiasG%C3%B6tzke/posts/9v9BMCJj2k6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!