2016-07-23 88 views
0

我需要以下条件: 如果我发送一个GET请求是这样的:PhantomJS get请求显示静态页面,而不是完全加载页面

page.open("<URL>",function (status) { 
    // If connection wasn't successful: 
    if (status !== 'success') { 
     console.log('Unable to access network'); 
    } else { 
     console.log(page.content) 
    } 
} 

我得到记录就像当你用鼠标右键单击页面和页面点击查看页面源代码....我需要它是当你打开Chrome浏览器内的开发人员工具,并看到所有的JavaScript完成的结果页面。可能吗?

+0

欢迎堆栈溢出!如果链接副本不适用于您...您使用哪个PhantomJS版本?请注册onConsoleMessage,onError,onResourceError,onResourceTimeout事件([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf#file-1_phantomerrors-js))。也许有错误。 –

回答

0

有一个onLoadFinished处理这应该给你的内容在页面完全加载后:

http://phantomjs.org/api/webpage/handler/on-load-finished.html

page.onLoadFinished = function(status) { 
    console.log('Status: ' + status); 
    if (status !== 'success') { 
    console.log('Unable to access network'); 
    } else { 
    console.log(page.content) 
    } 
}; 
+0

它实际上不提供我想要的。在我的网页上有很多'

'。如果我将'onLoadFinished'中的页面内容解析为DOM(HTML),'html.getElementsByClassName(“podSplashRow”)'的长度等于0 – duri

+0

在这种情况下,UI元素在页面加载完成后加载。你可以尝试'var html = page.evaluate(function(){return document.documentElement.outerHTML;}); console.log(html);' – mxlse

+0

它只是不给我想要的结果。我在开发人员工具中看到的许多元素在此代码中缺失,就像一些JavaScript没有进行或没有进行过什么。 – duri