利用PhantomJS做网页截图经济适用,但其API较少,做其他功能就比较吃力了。

CasperJs是对phantomjs的一次封装。即phantomjs是原生的,而casperjs是封装在以phantomjs基础上的玩意。

用CasperJS浏览页面比用PhantomJS更加方便和直观。

相关传送门:

# 官网
http://casperjs.org/ # github
https://github.com/casperjs/casperjs # 快速入门
http://docs.casperjs.org/en/latest/quickstart.html # API文档
http://docs.casperjs.org/en/latest/modules/index.html # Event事件API文档
http://docs.casperjs.org/en/latest/events-filters.html#events-reference
# 利用phantomjs+casperjs实现登陆抓取网页并截图
http://blog.csdn.net/longhaoyou/article/details/43524977 # 入门练习demo
http://blog.csdn.net/kiwi_coder/article/details/36248353 # 利用nodejs+phantomjs+casperjs采集淘宝商品的价格
http://www.cnblogs.com/xinzhyu/p/4214669.html # 萌萌CasperJS第1篇 1分钟写完爬虫 拿亚马逊商品数据
http://blog.csdn.net/sagomilk/article/details/20800543

# 解决乱码问题:

phantom.outputEncoding = "gbk";

# 利用open / AJAX发送HTTP请求

http://docs.casperjs.org/en/latest/modules/casper.html#open

http://docs.casperjs.org/en/latest/modules/clientutils.html#sendajax

# 监听页面的错误

phantom.outputEncoding = "gbk";
var casper = require('casper').create({
viewportSize: {width: , height: },
waitTimeout:
}); // 需要先申明,然后再start
casper.on('page.error', function (err) {
this.echo(err)
}) casper.start('http://localhost:8081/#/home', function () {
this.echo('Casper Starting');
}) casper.run();

# 快速判断元素是否存在

var casper = require('casper').create();

casper.start('http://domain.tld/page.html', function() {
if (this.exists('h1.page-title')) {
this.echo('the heading exists');
}
}); casper.run();

# 建议对click之后的验证加入wait操作。这样可以有更好的保证. 并且建议尽可能使用thenClick。除非点击的元素要在指定的区域

  // houseBusinessDetails
this.thenClick('.listviewItem:nth-child(1) .busitem').wait(, function () {
this.echo(this.getCurrentUrl());
this.capture('capture/houseBusinessDetails.png')
})

# 可以用thenOpen进行跳转界面

  // carBusiness
this.thenOpen('http://localhost:8081/#/carBusiness').waitForSelector('.listviewItem').wait(, function () {
this.echo(this.getCurrentUrl());
this.capture('capture/carBusiness.png')
})

个人练手笔记

phantom.outputEncoding = "gbk";
var casper = require('casper').create({
viewportSize: {width: 414, height: 736},
waitTimeout:30000,
}); const u = function () {
casper.echo("当前正在操作的URL为:" + casper.getCurrentUrl())
} // 需要先申明,然后再start
casper.on('page.error', function (err) {
this.echo("出现了error等级的错误信息------- " + err, 1);
}) casper.start('http://localhost:8081/', function () {
// Home
this.waitForSelector("#app .centers-sec", function () {
u()
this.capture('capture/home.png')
}) // houseBusiness
this.thenClick('.module:nth-child(1)').wait(1500, function () {
u()
this.capture('capture/houseBusiness.png')
}) // houseBusinessDetails
this.thenClick('.listviewItem:nth-child(1) .busitem').wait(1500, function () {
u()
this.capture('capture/houseBusinessDetails.png')
}) // carBusiness
this.thenOpen('http://localhost:8081/#/carBusiness').waitForSelector('.listviewItem').wait(1500, function () {
u()
this.capture('capture/carBusiness.png')
}) // CarBusinessDetails
this.thenClick('.listviewItem:nth-child(1) .busitem').wait(1500, function () {
u()
this.capture('capture/CarBusinessDetails.png')
}) // lentOutDetail
this.then(function () {
if (this.exists('#header .right-btn a')) {
this.thenClick('#header .right-btn a').wait(1500, function () {
u()
this.capture('capture/lentOutDetail.png')
})
}
}) // myBusiness
this.thenOpen('http://localhost:8081/#/myBusiness').wait(1500, function () {
u()
this.capture('capture/myBusiness0.png')
}).thenClick(".mint-tab-item:nth-child(2)").wait(2500, function () {
u()
this.capture('capture/myBusiness1.png')
}).thenClick(".mint-tab-item:nth-child(3)").wait(1000, function () {
u()
this.capture('capture/myBusiness2.png')
}) // userInfo
this.thenOpen('http://localhost:8081/#/user/userInfo').wait(1500, function () {
u()
this.capture('capture/userInfo.png')
}) // qrcode
this.thenOpen('http://localhost:8081/#/qrcode').wait(1500, function () {
u()
this.capture('capture/qrcode.png')
}) // allLedger
this.thenOpen('http://localhost:8081/#/allLedger').wait(3500, function () {
u()
this.capture('capture/allLedger.png')
}) // AutoRepay
this.thenOpen('http://localhost:8081/#/AutoRepay').wait(3500, function () {
u()
this.capture('capture/AutoRepay.png')
}) // auditAssign
this.thenOpen('http://localhost:8081/#/auditAssign').wait(2500, function () {
u()
this.capture('capture/auditAssign.png')
})
}) casper.run();

PhantomJs 与 Casperjs的更多相关文章

  1. [Python爬虫] 在Windows下安装PhantomJS和CasperJS及入门介绍(上)

    最近在使用Python爬取网页内容时,总是遇到JS临时加载.动态获取网页信息的困难.例如爬取CSDN下载资源评论.搜狐图片中的“原图”等,此时尝试学习Phantomjs和CasperJS来解决这个问题 ...

  2. PhantomJS、CasperJS安装配置图文详解

    目前网站主流的加载方式: 一种是同步加载:另一种是异步加载,也即我们常说的用ajax.对于同步加载的网站,普通的爬虫程序轻松就能搞定.但是对于那种异步请求数据的网站,通常使用selenium+Phan ...

  3. PhantomJS与CasperJS在Windows下的安装与使用

    按照网上的教程来呢,一定是不好使的,这是常理. 所以必须要告诉你怎么使用Phantomjs…… 这么用! 1.下载Phantomjs的压缩包并解压缩: 2.在bin目录(包含phantomjs.exe ...

  4. 前端端对端测试:基于PhantomJS的CasperJS

    简介 Casperjs是一个基于PhantomJS和SlimerJS的前端端对端测试框架,当然你也可以使用它完成网络爬虫功能,它的特点的通过简单的脚本模拟浏览器行为, 主要有casper.tester ...

  5. 浏览器自动化测试初探 - 使用phantomjs与casperjs

    收录待用,修改转载已取得腾讯云授权 作者:yangchunwen 首先要解释一下为什么叫浏览器自动化测试,因为本文只关注发布后页面功能的自动化测试,也就是UI层面的自动化. 浏览器测试有别于js代码的 ...

  6. [转] 浏览器自动化测试初探:使用 phantomjs 与 casperjs

    [From] https://www.qcloud.com/community/article/641602001489391648 作者:yangchunwen 首先要解释一下为什么叫浏览器自动化测 ...

  7. Phantomjs和Casperjs,后台网页抓取和交互

    var casper = require('casper').create({ verbose: true, logLevel: 'debug', pageSettings: { loadImages ...

  8. windows下面安装casperjs

    因为需要 就学习了一下casperjs,CasperJS是一个开源的导航脚本处理和测试工具,基于PhantomJS(前端自动化测试工具)编写.由于casperjs对PhantomJS的依赖性,所以需要 ...

  9. [Python爬虫] Selenium+Phantomjs动态获取CSDN下载资源信息和评论

    前面几篇文章介绍了Selenium.PhantomJS的基础知识及安装过程,这篇文章是一篇应用.通过Selenium调用Phantomjs获取CSDN下载资源的信息,最重要的是动态获取资源的评论,它是 ...

随机推荐

  1. [LeetCode] 116. 填充每个节点的下一个右侧节点指针

    题目链接 : https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node/ 题目描述: 给定一个完美二叉树 ...

  2. pL/Sql插入语句时报错,对表空间没有权限 对表空间 'USERS' 无权限

    进入dba为其授予权限:sqlplus sys/admin as sysdba; 为用户授予权限即可 grant unlimited tablespace to username;

  3. Maven 添加其他Maven组件配置问题

    在父工程的pom文件里,添加如下配置 <project> <!--其它配置--> <modules> <module>A项目文件夹</module ...

  4. 基于双XCKU060+双C6678 的双FMC接口40G光纤传输加速计算卡381

    一.板卡概述 板卡采用基于双FPGA+双DSP的信号采集综合处理硬件平台,板卡大小360mmx217mm.板卡两片FPGA提供两个FMC接口,4路QSFP+接口:每片FPGA挂接2簇32-bit DD ...

  5. js的cookie写入存储与读取

    js的cookie写入存储与读取 在路径url截取需要的数据,存储到cookie里,读取成功并实现跳转. //写cookies 过期时间 2小时后 function setCookie(c_name, ...

  6. TCP软件环境测试

    利用合宙官网上的云平台->TCP透传云,建立一个TCP服务. http://tcplab.openluat.com/ [注意事项] 如3分钟内没有客户端接入则会自动关闭. 每个服务器最大客户端连 ...

  7. POJ 3667 Hotel (线段树区间合并)

    题目链接:http://poj.org/problem?id=3667 题目大意:一共有n个房间,初始时都是空的,现在有m个操作,操作有以下两种: 1.1 d :询问是否有连续d个空的房间,若有则输出 ...

  8. IPv6是未来趋势?部署IPv6有什么技术障碍?

    没有人在用IPv6?我相信有很多人在谈话中听到了类似的内容,虽然很难说服这些人,越来越多的组织正在部署IPv6,特别是当采用率在20岁时如此缓慢到目前为止存在的一年,这些实例至少让我有机会让他们再次思 ...

  9. LeetCode--059--螺旋矩阵 II(python)

    效率超级低,但是能过.... class Solution: def generateMatrix(self, n): tR = tC = 0 dR = n-1 dC = n-1 x = [[0 fo ...

  10. 大数减法(A - B Problem Plus)问题

    解题思路 flagA为0表示A为正整数,为-1表示A为负整数: flagB为0表示B为正整数,为2表示B为负整数: 而 flag = flagA + flagB. 1.当 flag == 0 表示数A ...