使用casperjs抓取http://bm.scs.gov.cn/2015/StudentLogin.aspx
来源:互联网 发布:人工智能围棋柯洁 编辑:程序博客网 时间:2024/04/28 21:04
var casper = require('casper').create({ verbose: true, logLevel: 'debug', pageSettings: { userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:37.0) Gecko/20100101 Firefox/37.0', loadImages: true, loadPlugins: true }});//文件处理var fs = require('fs');casper.options.viewportSize = {width: 1680, height: 924};casper.start('http://bm.scs.gov.cn/2015/StudentLogin.aspx');casper.then(function(){ this.echo('开始获取cookie中的验证码'); var phantom_cookie = phantom.cookies; var cookie_info = ''; for (var i in phantom_cookie){ if(phantom_cookie[i]['name']=='ValicodeCookie'){ cookie_info = phantom_cookie[i]['value']; } } if(cookie_info !==''){ cookie_array = cookie_info.split('='); input = cookie_array[1]; }else{ input = ''; } this.echo('获取cookie中的验证码是'+input); this.sendKeys('form#Form1 input#Loginbystudent1_txt_vcode',input);});//casper.wait(5*1000,function init(){// this.echo('开始截图');// this.captureSelector('lo.jpeg','#Loginbystudent1_Image1');// this.echo('截图完成');//});////casper.then(function(){// this.echo('请输入验证码:');// var input = system.stdin.readLine();// this.echo('你输入的是:'+(input));// this.sendKeys('form#Form1 input#Loginbystudent1_txt_vcode',input);//});casper.waitForSelector("form#Form1", function success() { this.test.assertExists("form[id='Form1']"); this.fill('form[id="Form1"]',{ 'Loginbystudent1$txt_Identify':'username', 'Loginbystudent1$txtPassword':'password' },false); this.click("a#Loginbystudent1_btn_Login"); }, function fail() { this.test.assertExists("form[id='Form1']");});casper.waitFor(function check() { return this.getCurrentUrl().indexOf("http://bm.scs.gov.cn/2015/UserControl/")>-1;}, function then() { this.echo('登陆成功');}).then(function(){ //this.echo("打开链接并截图"); this.echo('当前的页面链接 ' + this.getCurrentUrl()); this.capture("./me.png");});//把cookie写入文件casper.wait(1000, function () { this.echo('保存cookie文件'); var cookies = JSON.stringify(phantom.cookies); cookie_file = 'login_cookie.txt'; fs.write(cookie_file, cookies, 644); this.echo("cookie写入成功 : " + cookie_file +"\n");});casper.run(function() {this.test.renderResults(true);});//casper.exit();
0 0
- 使用casperjs抓取http://bm.scs.gov.cn/2015/StudentLogin.aspx
- http://www.miibeian.gov.cn/
- http://www.xdz.gov.cn/info/20498/136013.htm
- .gov.cn网站集锦
- gov.cn成绩查询
- http://dotnet.mblogger.cn/w6f3y0/search.aspx
- FastReport问题整理(http://129.sqdj.gov.cn/?p=77)
- Linux设备文件(转自:http://lamp.linux.gov.cn/Linux/device_files.html)
- apache/C++ CGI动态页面 http://lamp.linux.gov.cn/Apache/ApacheMenu/howto/cgi.html
- 使用python/casperjs编写终极爬虫-客户端App的抓取
- 使用python/casperjs编写终极爬虫-客户端App的抓取
- 使用python/casperjs编写终极爬虫-客户端App的抓取
- 使用python/casperjs编写终极爬虫-客户端App的抓取
- casperjs页面抓取问题
- Windows下动态内存分配方式http://whx.tzgt.gov.cn/newOperate/html/7/71/711/3938.html
- www.miibeian.gov.cn 的PageRank
- [www.miibeian.gov.cn] Alexa综合排名
- http://msdn2.microsoft.com/zh-cn/library/default.aspx
- Android初学------选择设置壁纸的时候可以选择自己的应用
- 如何去掉Word空白页
- 系统入门(8):Activity创建Window和View分析
- Java Concrrency 定义不可变对象的策略
- Ruby method 学习笔记
- 使用casperjs抓取http://bm.scs.gov.cn/2015/StudentLogin.aspx
- Div 内容垂直居中
- 逆序数的拆分计算
- shell学习笔记之五(特殊字符)
- Leetcode_202_Happy Number
- 卡特兰数
- windows下文件编码和读写注意
- JSONArray JSONObject删除指定键值对
- git server搭建成功 & repo