CasperJS基于PhantomJS抓取页面
CasperJS基于PhantomJS抓取页面
Casperjs是基于Phantomjs的,而Phantom JS是一个服务器端的 JavaScript API 的 WebKit。
CasperJS是一个开源的,用JavaScript编写的,基于PhantomJS的导航脚本和测试工具 ,它简化了定义一个完成的导航操作所需的步骤,还提供了很有用的函数封装,方法,和语法糖,它可以完成下面这些常见任务:
定义 & 排序浏览器导航步骤
填充 & 提交表单
点击 & 跟踪链接
捕获网页截图 (还可以截取某一区域)
在远程DOM上进行断言测试
记录事件
下载资源,包括二进制文件
编写功能测试套件,结果保存为JUnit XML文件
抓取网页内容
CasperJS,基于PhantomJS的工具包 - 紫云飞 - 博客园
http://www.cnblogs.com/ziyunfei/archive/2012/09/27/2706254.html
后台连接网站和页面交互一下子变得异常简单起来。尤其是对需要登录才可进行的网页操作。
登录沪江英语自动打卡
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages: false,
loadPlugins: true,
userAgent: 'Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0'
}
});
//phantom.outputEncoding="gbk";
casper.options.viewportSize = {width: 1680, height: 924};
casper.start('http://bulo.hujiang.com/app/login?source=nbulo&returnurl=/home/');
casper.waitForSelector("form#myform input[name='txtUsername']",
function success() {
this.test.assertExists("form input[name='txtUsername']");
this.fill("form",{
'txtUsername':'shixiaobao17',
'txtPassword':'×××××your password*****'
},false);
this.click("input#btnLogin");
},
function fail() {
this.test.assertExists("form input[name='txtUsername']");
});
casper.waitFor(function check() {
return this.getCurrentUrl().indexOf("bulo.hujiang.com/home")>-1;
}, function then() {
console.log("登录成功!!!!!!!!!!!!");
}).then(function(){
console.log("执行登录后的其它操作!!!!!!!!!!!!");
if(this.exists("#btn_card_do")){
this.click("#btn_card_do");
this.waitForSelector("#my_hb_btn",function success(){
console.log("打卡成功!");
},function fail(){
console.log("打卡失败!");
});
}else{
console.log("今天已经打过卡啦!");
}
});
casper.run(function() {this.test.renderResults(true);});
CasperJS基于PhantomJS抓取页面的更多相关文章
- NodeJS + PhantomJS 抓取页面信息以及截图
利用PhantomJS做网页截图经济适用,但其API较少,做其他功能就比较吃力了.例如,其自带的Web Server Mongoose最高只能同时支持10个请求,指望他能独立成为一个服务是不怎么实际的 ...
- 基于Casperjs的网页抓取技术【抓取豆瓣信息网络爬虫实战示例】
CasperJS is a navigation scripting & testing utility for the PhantomJS (WebKit) and SlimerJS (Ge ...
- 基于puppeteer模拟登录抓取页面
关于热图 在网站分析行业中,网站热图能够很好的反应用户在网站的操作行为,具体分析用户的喜好,对网站进行针对性的优化,一个热图的例子(来源于ptengine) 上图中能很清晰的看到用户关注点在那,我们不 ...
- C#使用Selenium+PhantomJS抓取数据
本文主要介绍了C#使用Selenium+PhantomJS抓取数据的方法步骤,具有很好的参考价值,下面跟着小编一起来看下吧 手头项目需要抓取一个用js渲染出来的网站中的数据.使用常用的httpclie ...
- phantomjs 抓取、截图中文网站乱码的问题的解决
用phantomjs抓取html乱码的解决方案: phantomjs --output-encoding=gbk test.js http://webscan.360.cn/index/checkwe ...
- selenium+PhantomJS 抓取淘宝搜索商品
最近项目有些需求,抓取淘宝的搜索商品,抓取的品类还多.直接用selenium+PhantomJS 抓取淘宝搜索商品,快速完成. #-*- coding:utf-8 -*-__author__ =''i ...
- 爬虫抓取页面数据原理(php爬虫框架有很多 )
爬虫抓取页面数据原理(php爬虫框架有很多 ) 一.总结 1.php爬虫框架有很多,包括很多傻瓜式的软件 2.照以前写过java爬虫的例子来看,真的非常简单,就是一个获取网页数据的类或者方法(这里的话 ...
- 搭建谷歌浏览器无头模式抓取页面服务,laravel->php->python->docker !!!
背景: 公司管理系统需要获取企业微信页面的配置参数如企业名.logo.人数等信息并操作,来隐藏相关敏感信息并自定义简化企业号配置流程 第一版已经实现了扫码登录获取cookie,使用该cookie就能获 ...
- 用PHP抓取页面并分析
在做抓取前,记得把php.ini中的max_execution_time设置的大点,不然会报错的.
随机推荐
- github上所有大于800 star OC框架
https://github.com/XCGit/awesome-objc-frameworks#awesome-objc-frameworks awesome-objc-frameworks ID ...
- h5固定表头公共样式
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scal ...
- Docker网络基础
大量的互联网应用服务包括多个服务组件,这往往需要多个容器之间通过网络通信进行相互配合. Docker目前提供了映射容器端口到宿主主机和容器互联机制来为容器提供网络服务. 端口映射实现访问容器: 在启动 ...
- linux重置mysql密码
1.使用重置脚本 wget http://soft.vpser.net/lnmp/ext/reset_mysql_root_password.sh;sh reset_mysql_root_passwo ...
- Linux - sort & uniq
参考:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858385.html sort < InputFile | uniq -c
- SWIFT 闭包的简单使用二
import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...
- REST Security with JWT using Java and Spring Security
Security Security is the enemy of convenience, and vice versa. This statement is true for any system ...
- mysql management note
related url : http://willvvv.iteye.com/blog/1563345 http://lxneng.iteye.com/blog/451985 这篇文章对vari ...
- 常用<meta>标签
页面关键词 <meta name="keywords" content="your tags" /> 页面描述 <meta name=&quo ...
- ${pageContext.request.contextPath} JSP取得绝对路径
一.问题 JSP中究竟采用绝对路径还是采用相对路径随着所采用技术的越来越复杂,这个问题也变得越来越难以解决. 1)采用相对路径遇到的问题 相对路径固然比较灵活,但如果想复制页面内的代 ...