workdigital/casperjs-php-driver 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

workdigital/casperjs-php-driver

Composer 安装命令:

composer require workdigital/casperjs-php-driver

包简介

An improved general purpose PHP driver for CasperJS

README 文档

README

Build status

Prerequisites

This driver will assume that the command casperjs is available in your $PATH. If not, you can install it with:

npm install -g casperjs

Installation

You can use this package in your project via composer. Add these lines to your composer.json:

"require": {
  "workdigital/casperjs-php-driver": "1.*"
},
…

Latest stable release is 1.0

Examples

Basic usage

$driver = new CasperJs\Driver();
$output = $driver->start('http://someurl.com')
                 ->run();

Setting request parameters and interacting with the page

The entire point of using a tool like Casper is to be able to properly interact with the DOM for both testing and scraping purposes. This driver tries to expose a friendly interface to do so where you can define both request params and DOM interaction before making the actual call.

$driver = new CasperJs\Driver();
$driver->start('http://someurl.com')
       ->setUserAgent('AmericanPizzaiolo')
       ->setHeaders([
           'Accept-Language' => ['en-US'],
           'Some-Header' => 'Foo-bar',
       ])
       ->evaluate('make me a pizza')
       ->setViewPort(1024, 768)
       ->waitForSelector('.selector', 30000)
       ->wait(10000)
       ->click('.selector');

$output = $driver->run();

Using a proxy for your call

$driver = new CasperJs\Driver();
$driver->start('http://someurl.com')
       ->useProxy('1.1.1.1');

$output = $driver->run();

Getting the Casper Output

Whenever you execute Driver::run() the Driver will return an Output object that will encapsulate the Casper output. Output will expose the captured casper data or throw an exception in case the desired behaviour wasn't performed (i.e. if a css selector to be present in the page after timeout expired).

Extracting Data

$html = $output->getHtml();
$statusCode = $output->getStatusCode();
$currentUrl = $output->getCurrentUrl();

More examples

For more examples check out test/DriverTest.php

Credits

This driver is essentially an enhanced and improved version of the original alwex/php-casperjs.

workdigital/casperjs-php-driver 适用场景与选型建议

workdigital/casperjs-php-driver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.88k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 workdigital/casperjs-php-driver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 workdigital/casperjs-php-driver 我们能提供哪些服务?
定制开发 / 二次开发

基于 workdigital/casperjs-php-driver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14.88k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 25
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-07-27