首页 > Web开发 > 详细

casper爬虫操作记录

时间:2016-05-01 09:51:05      阅读:303      评论:0      收藏:0      [点我收藏+]
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();

  

casper爬虫操作记录

原文:http://www.cnblogs.com/caoke/p/5450045.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!