【问题标题】:How to get HTML content using PhantomJS after X seconds?如何在 X 秒后使用 PhantomJS 获取 HTML 内容?
【发布时间】:2018-12-16 12:53:15
【问题描述】:

如何使用 PhantomJS 在 10 秒后获取网站内容?例如,在我的网站中,我有执行 setTimeout 然后更改 DOM 的脚本。我需要使用该更改来获取网站 html。

我找不到任何有效的答案。

【问题讨论】:

标签: javascript html node.js phantomjs web-crawler


【解决方案1】:

试试这个代码:

var page = require('webpage').create();
var fs = require('fs');
page.open('http://example.com', function(status) {
    console.log('Page load status: ' + status);
    if (status === 'success') {
        setTimeout(function(){
            fs.write('example.html', page.content, 'a');
            console.log('Page saved');
            phantom.exit();
        }, 10000);
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-11
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多