Поиск по блогу

суббота, 30 мая 2015 г.

Устанавливаем Casperjs на Debian (Kali) из GitHub и находим способ "phantomjs casperscript.js"

Установка простая, если не считать того, что CasperJS version 1.1.0-beta3 at /usr/local/share/casperjs, using phantomjs version 1.9.8 (Casper пока рабтает только с предыдущей версия Phantom). Кроме того, я решил выполнять скрипты casper из консоли REPL, для этого учусь запускать касперскрипты в командной строке phantomjs.
Хотя, пробовать будем потом, здесь только краткие фрагменты из документации.

В документации вот такие команды

In [ ]:
 git clone git://github.com/n1k0/casperjs.git
$ cd casperjs
$ ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs

Я не смог найти, что занчит 'pwd' и решил, вместо выполнения последней неясной команды, установить Casperjs туда же, куда и Phantomjs

In [ ]:
root@kali:~# git clone git://github.com/n1k0/casperjs.git
Cloning into 'casperjs'...
remote: Counting objects: 13597, done.
remote: Total 13597 (delta 0), reused 0 (delta 0), pack-reused 13597
Receiving objects: 100% (13597/13597), 8.81 MiB | 1.89 MiB/s, done.
Resolving deltas: 100% (7830/7830), done.
root@kali:~# 

Передвинем все в ту же папку, где уже лежит phantomjs

In [ ]:
root@kali:~# mv casperjs /usr/local/share

Теперь создадим символическую ссылку

In [ ]:
root@kali:~# ln -sf /usr/local/share/casperjs/bin/casperjs /usr/local/bin/casperjs
In [ ]:
root@kali:~# casperjs
CasperJS version 1.1.0-beta3 at /usr/local/share/casperjs, using phantomjs version 1.9.8
Usage: casperjs [options] script.[js|coffee] [script argument [script argument ...]]
       casperjs [options] test [test path [test path ...]]
       casperjs [options] selftest
       casperjs [options] __selfcommandtest

Options:

--verbose   Prints log messages to the console
--log-level Sets logging level
--help      Prints this help
--version   Prints out CasperJS version
--engine=name Use the given engine. Current supported engine: phantomjs and slimerjs

Read the docs http://docs.casperjs.org/

root@kali:~# 

Yes, you can call a CasperJS script directly with the phantomjs executable, but if you do so, you must set the phantom.casperPath property to the path where the library root is located on your system:

In [ ]:
/ casperscript.js
phantom.casperPath = '/path/to/casperjs';
phantom.injectJs(phantom.casperPath + '/bin/bootstrap.js');

var casper = require('casper').create();
// ...
In [ ]:
#You can run such a script like any other standard PhantomJS script:
$ phantomjs casperscript.js

If you’re on Windows, this is the way you may manage to get casper working the most easily:

In [ ]:
phantom.casperPath = 'C:\\path\\to\\your\\repo\\lib\\casperjs-0.6.X';
phantom.injectJs(phantom.casperPath + '\\bin\\bootstrap.js');

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

// do stuff

Приложение. Пытаюсь понять, что значит ln -sf pwd/bin/casperjs /usr/local/bin/casperjs

In [1]:
!ln --help
Usage: ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
  or:  ln [OPTION]... TARGET                  (2nd form)
  or:  ln [OPTION]... TARGET... DIRECTORY     (3rd form)
  or:  ln [OPTION]... -t DIRECTORY TARGET...  (4th form)
In the 1st form, create a link to TARGET with the name LINK_NAME.
In the 2nd form, create a link to TARGET in the current directory.
In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.
Create hard links by default, symbolic links with --symbolic.
When creating hard links, each TARGET must exist.  Symbolic links
can hold arbitrary text; if later resolved, a relative link is
interpreted in relation to its parent directory.

Mandatory arguments to long options are mandatory for short options too.
      --backup[=CONTROL]      make a backup of each existing destination file
  -b                          like --backup but does not accept an argument
  -d, -F, --directory         allow the superuser to attempt to hard link
                                directories (note: will probably fail due to
                                system restrictions, even for the superuser)
  -f, --force                 remove existing destination files
  -i, --interactive           prompt whether to remove destinations
  -L, --logical               make hard links to symbolic link references
  -n, --no-dereference        treat destination that is a symlink to a
                                directory as if it were a normal file
  -P, --physical              make hard links directly to symbolic links
  -s, --symbolic              make symbolic links instead of hard links
  -S, --suffix=SUFFIX         override the usual backup suffix
  -t, --target-directory=DIRECTORY  specify the DIRECTORY in which to create
                                the links
  -T, --no-target-directory   treat LINK_NAME as a normal file
  -v, --verbose               print name of each linked file
      --help     display this help and exit
      --version  output version information and exit

The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable.  Here are the values:

Using -s ignores -L and -P.  Otherwise, the last option specified controls
behavior when the source is a symbolic link, defaulting to -P.

  none, off       never make backups (even if --backup is given)
  numbered, t     make numbered backups
  existing, nil   numbered if numbered backups exist, simple otherwise
  simple, never   always make simple backups

Report ln bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'ln invocation'

Из info ln ... понятно, что ссылка может содежать строку, но не пойму сходу, зачем? ... Надеюсь, как нибудь потом дойдет...

In [ ]:
   Symbolic links can contain arbitrary strings; a "dangling symlink"
occurs when the string in the symlink does not resolve to a file.
There are no restrictions against creating dangling symbolic links.
There are trade-offs to using absolute or relative symlinks.  An
absolute symlink always points to the same file, even if the directory
containing the link is moved.  However, if the symlink is visible from
more than one machine (such as on a networked file system), the file
pointed to might not always be the same.  A relative symbolic link is
resolved in relation to the directory that contains the link, and is
often useful in referring to files on the same device without regards
to what name that device is mounted on when accessed via networked
machines.


Посты чуть ниже также могут вас заинтересовать

Комментариев нет:

Отправить комментарий