您的位置:首页 > 编程语言 > ASP

casper爬虫操作记录

2016-05-01 09:12 477 查看
phantom.outputEncoding = "gbk";
var fs=require("fs")

//var data = fs.read("cookie.txt")
//phantom.cookies = JSON.parse(data)

var casper = require("casper").create({
clientScripts: ["jquery.min.js"],
verbose: true,
//    logLevel: 'debug',
safeLogs: true,
viewportSize:{width: 1024, height: 768},
pageSettings: {
//        loadImages: false, // The WebPage instance used by Casper will
//        loadPlugins: false, // use these settings
userAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36'
}
})                       //新建一个页面

casper.start('http://www.cnblogs.com/pick/');
casper.then(function(){
this.evaluate(function() {
$("a:contains('登录')").click()
});
this.wait(1000, function() {
this.echo("I've waited for a second.");
});
})
casper.then(function(){
this.capture('qq2.png');
console.log(210)
this.evaluate(function() {
$("#input1").focus().val("m3m4_ck")
$("#input2").focus().val("保密")
$("#signin").click()
});
this.wait(1000, function() {
this.echo("I've waited for a second.");
});
})
casper.then(function(){
this.capture('qq3.png');
})

casper.then(function(){
this.wait(2000,function(){
this.capture('qq4.png');
var cookies = JSON.stringify(phantom.cookies)
fs.write("cookie.txt", cookies, 644)
})
//    this.fill('#Main form', {
//        'text':    'm3m4_ck',
//        'password':    '907167'
//    }, false);
//    this.click("#signin")
//
//
//    this.wait(5000,function(){
//        var cookies = JSON.stringify(phantom.cookies)
//        fs.write("cookie.txt", cookies, 644)
//        this.capture('qq2.png');
//    })

});

casper.run();


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: