zoukankan      html  css  js  c++  java
  • casper爬虫操作记录

    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:{ 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();
    

      

  • 相关阅读:
    【jQuery】清空表单内容
    【jQuery】remove()和empty()的使用
    【ajax 提交表单】多种方式的注意事项 ,serialize()的使用
    【Gson】互相转化
    yum安装nginx详解
    linux find命令
    nginx实战
    java判断是否为汉字
    分布式存储 CentOS6.5虚拟机环境搭建FastDFS-5.0.5集群(转载)
    Java应用程序实现屏幕的"拍照"
  • 原文地址:https://www.cnblogs.com/caoke/p/5450045.html
Copyright © 2011-2022 走看看