最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Rendering a javascript webpage page with phantomjs - Stack Overflow

programmeradmin5浏览0评论

I am trying to render a a javascript evaluated source code from a website using phantomjs. But every time I try i only get the source code as is (similar to view source from the browser). What I actually want is the javascript evaluated code (what we see from inspect element from google chrome browser). My code looks like this:

var page = require('webpage').create();
page.open('/', function (s) {
    console.log(page.content);
    phantom.exit();
});

Am I doing something wrong here?

I am trying to render a a javascript evaluated source code from a website using phantomjs. But every time I try i only get the source code as is (similar to view source from the browser). What I actually want is the javascript evaluated code (what we see from inspect element from google chrome browser). My code looks like this:

var page = require('webpage').create();
page.open('http://www.google./', function (s) {
    console.log(page.content);
    phantom.exit();
});

Am I doing something wrong here?

Share Improve this question asked Feb 28, 2013 at 16:45 TranceyTrancey 7092 gold badges8 silver badges19 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

This did the trick for me:

window.setTimeout(function () {
        page.render(output);
        phantom.exit();
    }, 1000);

Likely yes. In many cases, the JavaScript code on the web page is not executed immediately. You can take this into account by giving a little delay, e.g. using setTimeout, before taking the value of page.content.

发布评论

评论列表(0)

  1. 暂无评论