phantomjs

package module
v0.0.0-...-3d4b53e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2014 License: MIT Imports: 11 Imported by: 4

README

go-phantomjs

A tiny phantomjs wrapper for go

Usage

import (
  "github.com/urturn/go-phantomjs" // exported package is phantomjs
)

func main() {
  p, err := phantomjs.Start()
  if err != nil {
    panic(err)
  }
  defer p.Exit() // Don't forget to kill phantomjs at some point.
  var result interface{}
  err = p.Run("function() { return 2 + 2 }", &result)
  if err != nil {
    panic(err)
  }
  number, ok := result.(float64)
  if !ok {
    panic("Cannot convert result to float64")
  }
  fmt.Println(number)
  // Output: 4
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

Types

type Phantom

type Phantom struct {
	// contains filtered or unexported fields
}

func Start

func Start(args ...string) (*Phantom, error)

Create a new `Phantomjs` instance and return it as a pointer.

If an error occurs during command start, return it instead.

func (*Phantom) Exit

func (p *Phantom) Exit() error

Exit Phantomjs by sending the "phantomjs.exit()" command and wait for the command to end.

Return an error if one occured during exit command or if the program output a error value

func (*Phantom) Load

func (p *Phantom) Load(jsCode string) error

Eval `jsCode` in the main context.

func (*Phantom) Run

func (p *Phantom) Run(jsFunc string, res *interface{}) error

Run the javascript function passed as a string and wait for the result.

The result can be either in the return value of the function or the first argument passed to the function first arguments.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL