小编ron*_*ils的帖子

单击带有 phantom.js 的链接并检索文档 html

我是 phantom.js 的新手,我试图在网站页面上导航,点击一个链接(调用 AJAX 函数并更改文档 HTML)与 phantom.js。

这是我的代码:

window.setTimeout(function(){
    phantom.exit();
}, 120000);

var page = require('webpage').create();

page.open("http://example.com", function(status) {
    if (status !== 'success') {
        console.log('{"error":"Unable to load the address for page"}');
        phantom.exit();
    }

    var action = page.evaluate(function() {
        document.getElementById("anID").click();
        return "clicked";
    });

    var results = page.evaluate(function() {
        return document.documentElement.innerHTML;
    });

    console.log(action);

    window.setInterval(function() {
        console.log(results);
        phantom.exit();
    }, 3000);
});
Run Code Online (Sandbox Code Playgroud)

我很困惑,因为在我的“动作”函数中,click() 调用引发了重复 3 次的错误:

TypeError: 'undefined' 不是函数
phantomjs://webpage.evaluate():3 phantomjs://webpage.evaluate():1
ph.js:121 null

TypeError: 'undefined' 不是函数
phantomjs://webpage.evaluate():3 phantomjs://webpage.evaluate():1
ph.js:121 null

TypeError: 'undefined' 不是函数
phantomjs://webpage.evaluate():3 …

javascript ajax jquery phantomjs

4
推荐指数
1
解决办法
7699
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1

phantomjs ×1