GithubHelp home page GithubHelp logo

casperjs-php-driver's Introduction

CasperJS PHP Driver

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.

casperjs-php-driver's People

Contributors

arlingtonhouse avatar fguery avatar jnardiello avatar putzy avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

casperjs-php-driver's Issues

Blank Response Laravel

Hello,

I have casperjs and phantomjs installed globally.
I run Laravel 5.2 with nginx - ubuntu 16.04
I have tried everything, even setting the path manually and installing casperjs in the public folder. All i get is a blank response.

The path to the executable is correct, because if i set it wrong i get an error.

Both phantom and casper work from the command line.

Locating casperjs binary

I have problems with exec in your file Driver.php, line 65.

this is not working both on my server and local mac

exec('casperjs ' . $filename . $this->optionBuilder->build(), $output);

But when i change it to this, it works

exec('/usr/local/bin/casperjs ' . $filename . $this->optionBuilder->build(), $output);

I think that this is because PHP doesn't know where to find casperjs executable file. Any idea how to solve this? Or at least to have this as optional configurable option, so it can be adjusted?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.