在CasperJS或PhantomJS中获取资源内容 [英] Grab the resource contents in CasperJS or PhantomJS

查看:72
本文介绍了在CasperJS或PhantomJS中获取资源内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到CasperJS具有下载"功能和在收到资源时"回调,但是在回调中看不到资源的内容,并且我不想将资源下载到文件系统. /p>

我想获取资源的内容,以便可以在脚本中对其进行处理. CasperJS或PhantomJS是否可能?

解决方案

我没有意识到我可以像这样从文档对象中获取源代码:

casper.start(url, function() {
    var js = this.evaluate(function() {
        return document; 
    }); 
    this.echo(js.all[0].outerHTML); 
});

更多信息此处.

>

I see that CasperJS has a "download" function and an "on resource received" callback but I do not see the contents of a resource in the callback, and I don't want to download the resource to the filesystem.

I want to grab the contents of the resource so that I can do something with it in my script. Is this possible with CasperJS or PhantomJS?

解决方案

Did not realize I could grab the source from the document object like this:

casper.start(url, function() {
    var js = this.evaluate(function() {
        return document; 
    }); 
    this.echo(js.all[0].outerHTML); 
});

More info here.

这篇关于在CasperJS或PhantomJS中获取资源内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆