【今更】エックスサーバーでphantomjsを使えるようにしてみた

本ページにはプロモーションが含まれています。
XSERVER

Xserver,python3,selenium,phantomjsの組合せです。

>レンタルサーバーにphp-phantomjsをインストールする方法はこちら

最初に明記しておきますが、
PhantomJSのサポートが終了しているので、他のheadlessを使ったほうがいいです。
Warningが出ます。
(Xserverなら、現状、諦めるしかありません。ここまでやるならVPSにしろ、ということ。でもphantomjsは使えました。)

UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
warnings.warn(‘Selenium support for PhantomJS has been deprecated, please use headless ‘

Xserverの環境

・Xserverにsshできること
参考記事:エックスサーバーのSSH接続を自動にする方法

・Xserverにanaconda環境を作ってあること
参考記事:エックスサーバーにpythonのライブラリーをインストールする(pipを使いたかった)
参考記事:エックスサーバーでanacondaでもpip install がエラーになった

Xserverにphantomjsを入れる手順

1.wgetします。(半角英字だと501エラーがでるので、全角wgetにしています。どうでもいいか。)

w g e t https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2

2.tarで解凍。

tar jxfv phantomjs-2.1.1-linux-x86_64.tar.bz2

3.解凍されたフォルダbinにあるphantomjsをパスのとおっているどこかへコピー。

cp -p phantomjs-2.1.1-linux-x86_64/bin/phantomjs /home/hogehoge/local/bin/

4.うまくいくと以下のようになります。

[hogehoge@xserver ~]$ phantomjs
phantomjs>

レンタルサーバーでもやってみればできるもんだ。
やっぱり、便利なんですよね。。。

レンサバなのにここまでできてしまうエックスサーバー、便利です。

>>エックスサーバーの各プラン(X10、X20、X30)の5つ違い

WebDriverException: Message: ‘phantomjs’ executable needs to be in PATH.

ちなみに、こんなエラー↓(手動実行ではうまくいったけど、cronで実行されるとエラーになりました)

WebDriverException: Message: ‘phantomjs’ executable needs to be in PATH.

が出る場合は、phantomjsにexecutable_path=を指定してやるとよい。

hogepath = '/home/hogehoge/local/bin/phantomjs'
driver = webdriver.PhantomJS(executable_path=hogepath)

では。

コメント

タイトルとURLをコピーしました