【问题标题】:Extracting dynamic content with node.js and PhantomJS使用 node.js 和 PhantomJS 提取动态内容
【发布时间】:2014-12-26 11:30:20
【问题描述】:

我想用 nodejs 和 phantomjs 控制台记录网页的内容。这是我的代码:

var phantom = require('phantom');

phantom.create(function(ph) {
    return ph.createPage(function(page) {
        return page.open("http://zehinz.com/test.html", function(status) {
            if (status === 'success') {
               //console.log the content of page with Javascript executed ???
            } else {
                console.log('some error');
                ph.exit();
            }
        });
    });
});

如何输出动态呈现的网页内容?

【问题讨论】:

    标签: javascript node.js phantomjs screen-scraping


    【解决方案1】:

    在普通的 PhantomJS 中,可以使用 page.content,但由于您使用的是桥接器,因此必须在后台从 PhantomJS 进程中显式获取 content 属性。您可以使用page.get 来执行此操作。

    在你的情况下,这是

    page.get('content', function(content){
        console.log("Content", content);
        ph.exit();
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 2020-08-25
    相关资源
    最近更新 更多