如何解决Casperjs资源已加载,但仍未定义功能
我正在尝试使用casperJS屏幕抓取一些数据。
我已经通过发帖成功登录了网站。
一旦我进入我的站点,所有内容都将通过ajax运行。页面网址永远不会更改,但dom会更新。
登录后,我有一个搜索框,然后有一个按钮来运行搜索。我可以用搜索词更新搜索框,但是,当我单击按钮时,它确实提供了pageError
并说Page Error: ReferenceError: Can't find variable: myfunc
但是,myfunc
是一个函数,已通过外部js成功加载文件(通过HTTPS)
这是示例代码:
var casper = require('casper').create({
verbose: true,logLevel: 'debug',viewportSize: {width: 1280,height: 800},pageSettings: {
//loadImages: false,// The WebPage instance used by Casper will
//loadPlugins: false,// use these settings
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML,like Gecko) Chrome/22.0.1229.94 Safari/537.4'
}
});
// print out all the messages in the headless browser context
casper.on('remote.message',function(msg) {
this.echo('remote message caught: ' + msg);
});
// print out all the messages in the headless browser context
casper.on("page.error",function(msg,trace) {
this.echo("Page Error: " + msg,"ERROR");
});
casper.on("resource.error",function(resourceError) {
//this.echo("REcource Error: " + msg,"ERROR");
this.echo('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
});
casper.on('resource.received',function(resource) {
var status = resource.status;
casper.log('Resource received ' + resource.url + ' (' + status + ')');
this.echo('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: '+ resource.url)
});
var url= "example.com"
casper.start(url,function() {
console.log("page loaded");
this.fill('form#loginForm',{
username: 'USER',password: 'PASS'
},true);
});
casper.thenEvaluate(function(id,type){
document.getElementById("search").value = 'search';
document.getElementById("submit").click();
})
//ALSO tried this but no use
casper.then(function(){
//this line makes a call to myfunc() which is already loaded in resource but it's not found during run time
this.click("a#submit");
})
运行此命令时,我得到Page Error: ReferenceError: Can't find variable: myFunc
PS:我的网站是HTTPS网站,我正在 casperjs --ignore-ssl-errors=yes myCaspFile.js
上运行casper。我所有的资源都基于HTTPS。
非常感谢任何指针。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。