问题描述
我正在尝试使用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 (将#修改为@)