LoginSignup
10
7

More than 5 years have passed since last update.

phantomJSを1からインストールする

Last updated at Posted at 2017-09-08

※ 【注釈】2017/9/10現在、PhantomJSの開発は公式にメンテナンス停止がアナウンスされているそうです。
JSを用いたスクレイピングであれば「nightmare」「puppeteer」を使用したほうが良いらしい。(Quramy様ご指摘ありがとうございます。)
nightmare ⇨ https://github.com/segmentio/nightmare
puppetter ⇨ https://github.com/GoogleChrome/puppeteer


最初はmechanizeでスクレイピングしようとしてました。ただ、JSによって動的に生成されたページに対応できなかった(僕の技術力では)ので、他の方法を探していたところ、phantomJSに出会ったわけです。

諸々のインストール

phantomJSを使うのに必要な諸々をインストールしていきます。Homebrewは入っている前提です。

  • まずはnode.JSのインストールから。 その前に複数バージョンを管理するためにnodebrewをインストール
terminal
$ brew install nodebrew
$ nodebrew setup //これをしないと次のコマンドでエラー吐く。必要なフォルダ等々を生成してくれるらしい
  • nodebrewのパスを通す
terminal
$ nodebrew setup
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew

========================================
Export a path to nodebrew:

export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================

と出てくるので、言われるとおりにパスをbash_profileに書き込んで、読み込み。

terminal
$ echo export PATH=$HOME/.nodebrew/current/bin:$PATH >> ~/.bash_profile //書き込み
$ source ~/.bash_profile //読み込み
  • (やっと)node.jsのインストール
terminal
$ nodebrew install-binary latest //最新版のインストール

//もしくは

$ nodebrew install-binary stable //安定版のインストール
  • 使用するnode.jsのバージョンを指定
terminal
$ nodebrew list
v8.4.0

current: none 
//⇑これが指定されていない状態

$ nodebrew use v8.4.0 //使用するバージョンを指定。

$ nodebrew list
v8.4.0

current: v8.4.0
//⇑無事指定できました
  • npmの生存確認
terminal
$ npm -v
5.3.0 //生きてた
  • npmを用いたphantomJSのインストール
terminal
$ npm install -g phantomjs //ようやっとインストール
  • phantomjsの生存確認
terminal
$ phantomjs -v
2.1.1 //生きてた

以上です、次はこれを使っていきたい

10
7
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7