ubuntu@AWS_TEST: ~] npm ← npmコマンドで既にインストールされているかチェック。インストールされていませんでした。
The program ‘npm’ is currently not installed. You can install it by typing:
sudo apt install npm
ubuntu@AWS_TEST: ~] sudo apt install npm ← aptコマンドで npm をインストールします。
Reading package lists… Done
Building dependency tree
Reading state information… Done
~ 省略 ~
Setting up npm (3.5.2-0ubuntu4) …
Processing triggers for libc-bin (2.23-0ubuntu10) …
ubuntu@AWS_TEST: ~]
npm とは何か?
npm コマンドは Node.js のパッケージを管理するコマンド(管理ツール)です。
npm は「Node Packaged Modules」の略です。
nodejs-legacy がインストールされていない場合はインストールする
次に「nodejs-legacy」パッケージをインストールします。
ubuntu@AWS_TEST: ~] sudo apt-get install nodejs-legacy
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following NEW packages will be installed:
nodejs-legacy
0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
Need to get 27.7 kB of archives.
After this operation, 81.9 kB of additional disk space will be used.
Get:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 nodejs-legacy all 4.2.6~dfsg-1ubuntu4.1 [27.7 kB]
Fetched 27.7 kB in 0s (56.8 kB/s)
Selecting previously unselected package nodejs-legacy.
(Reading database … 89150 files and directories currently installed.)
Preparing to unpack …/nodejs-legacy_4.2.6~dfsg-1ubuntu4.1_all.deb …
Unpacking nodejs-legacy (4.2.6~dfsg-1ubuntu4.1) …
Processing triggers for man-db (2.7.5-1) …
Setting up nodejs-legacy (4.2.6~dfsg-1ubuntu4.1) …
ubuntu@AWS_TEST: ~]
Considering PhantomJS found at /usr/local/bin/phantomjs
Looks like an `npm install -g`
Error checking path, continuing { [Error: Cannot find module ‘/usr/local/lib/node_modules/phantomjs/lib/location’] code: ‘MODULE_NOT_FOUND’ }
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1//phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving…
[===================================—–] 88%
Received 22866K total.
Extracting tar contents (via spawned process)
Removing /usr/local/lib/node_modules/phantomjs/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1516516076473/phantomjs-2.1.1-linux-x86_64 -> /usr/local/lib/node_modules/phantomjs/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs
/usr/local/lib mqw phantomjs@2.1.7 tqw extract-zip@1.5.0 x tqw concat-stream@1.5.0 x x tqq inherits@2.0.3 x x tqw readable-stream@2.0.6 x x x tqq core-util-is@1.0.2 x x x tqq isarray@1.0.0 x x x tqq process-nextick-args@1.0.7 x x x tqq string_decoder@0.10.31 x x x mqq util-deprecate@1.0.2 x x mqq typedarray@0.0.6 x tqq debug@0.7.4 x tqw mkdirp@0.5.0 x x mqq minimist@0.0.8 x mqw yauzl@2.4.1 x mqw fd-slicer@1.0.1 x mqq pend@1.2.0 tqw fs-extra@0.26.7 x tqq graceful-fs@4.1.11 x tqq jsonfile@2.4.0 x tqq klaw@1.3.1 x tqq path-is-absolute@1.0.1 x mqw rimraf@2.6.2 x mqw glob@7.1.2 x tqq fs.realpath@1.0.0 x tqw inflight@1.0.6 x x mqq wrappy@1.0.2 x tqw minimatch@3.0.4 x x mqw brace-expansion@1.1.8 x x tqq balanced-match@1.0.0 x x mqq concat-map@0.0.1 x mqq once@1.4.0 tqw hasha@2.2.0 x tqq is-stream@1.1.0 x mqw pinkie-promise@2.0.1 x mqq pinkie@2.0.4 tqq kew@0.7.0 tqq progress@1.1.8 tqw request@2.67.0 x tqq aws-sign2@0.6.0 x tqq bl@1.0.3 x tqq caseless@0.11.0 x tqw combined-stream@1.0.5 x x mqq delayed-stream@1.0.0 x tqq extend@3.0.1 x tqq forever-agent@0.6.1 x tqw form-data@1.0.1 x x mqw async@2.6.0 x x mqq lodash@4.17.4 x tqw har-validator@2.0.6 x x tqw chalk@1.1.3 x x x tqq ansi-styles@2.2.1 x x x tqq escape-string-regexp@1.0.5 x x x tqw has-ansi@2.0.0 x x x x mqq ansi-regex@2.1.1 x x x tqq strip-ansi@3.0.1 x x x mqq supports-color@2.0.0 x x tqq commander@2.13.0 x x mqw is-my-json-valid@2.17.1 x x tqq generate-function@2.0.0 x x tqw generate-object-property@1.2.0 x x x mqq is-property@1.0.2 x x tqq jsonpointer@4.0.1 x x mqq xtend@4.0.1 x tqw hawk@3.1.3 x x tqq boom@2.10.1 x x tqq cryptiles@2.0.5 x x tqq hoek@2.16.3 x x mqq sntp@1.0.9 x tqw http-signature@1.1.1 x x tqq assert-plus@0.2.0 x x tqw jsprim@1.4.1 x x x tqq assert-plus@1.0.0 x x x tqq extsprintf@1.3.0 x x x tqq json-schema@0.2.3 x x x mqw verror@1.10.0 x x x mqq assert-plus@1.0.0 x x mqw sshpk@1.13.1 x x tqq asn1@0.2.3 x x tqq assert-plus@1.0.0 x x tqq bcrypt-pbkdf@1.0.1 x x tqw dashdash@1.14.1 x x x mqq assert-plus@1.0.0 x x tqq ecc-jsbn@0.1.1 x x tqw getpass@0.1.7 x x x mqq assert-plus@1.0.0 x x tqq jsbn@0.1.1 x x mqq tweetnacl@0.14.5 x tqq is-typedarray@1.0.0 x tqq isstream@0.1.2 x tqq json-stringify-safe@5.0.1 x tqw mime-types@2.1.17 x x mqq mime-db@1.30.0 x tqq node-uuid@1.4.8 x tqq oauth-sign@0.8.2 x tqq qs@5.2.1 x tqq stringstream@0.0.5 x tqq tough-cookie@2.2.2 x mqq tunnel-agent@0.4.3 tqw request-progress@2.0.1 x mqq throttleit@1.0.0 mqw which@1.2.14 mqq isexe@2.0.0
ubuntu@AWS_TEST: /bin] phantomjs –version
/usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory
ubuntu@AWS_TEST: /bin]
上記のように「libfontconfig」ライブラリが見つからなくてエラーになっています。
libfontconfig ← generic font configuration library(一般的なフォント設定のライブラリ)
ubuntu@AWS_TEST: ~/dl] python3.6 scrape2.py /usr/local/lib/python3.6/dist-packages/selenium/webdriver/phantomjs/webdriver.py:49: 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 ‘ Here is some important text you want to retrieve!
A button to click!
ubuntu@AWS_TEST: ~/dl]
プログラムは問題なく実行されたのですが以下のメッセージが気になります。
「/usr/local/lib/python3.6/dist-packages/selenium/webdriver/phantomjs/webdriver.py:49: 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 ‘ Here is some important text you want to retrieve!」
# ユーザーエージェント
dcap[“phantomjs.page.settings.userAgent”] = (“Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1”)
ubuntu@AWS_TEST: ~/dl] python3.6 scrape2.py https://www.yahoo.co.jp
URLは https://www.yahoo.co.jp です。
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/phantomjs/webdriver.py:49: 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 ‘
<html lang=”ja” class=”is-iOS is-gteIOS7 is-iOS9 is-vtestIdMtop128″>
npm ERR! phantomjs@2.1.7 install: `node install.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the phantomjs@2.1.7 install script ‘node install.js’.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the phantomjs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node install.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs phantomjs
npm ERR! Or if that isn’t available, you can get their info via:
npm ERR! npm owner ls phantomjs
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/ubuntu/npm-debug.log
ubuntu@AWS_TEST: ~]
ubuntu@AWS_TEST: ~] sudo apt-get install nodejs-legacy
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following NEW packages will be installed:
nodejs-legacy
0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
Need to get 27.7 kB of archives.
After this operation, 81.9 kB of additional disk space will be used.
Get:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 nodejs-legacy all 4.2.6~dfsg-1ubuntu4.1 [27.7 kB]
Fetched 27.7 kB in 0s (56.8 kB/s)
Selecting previously unselected package nodejs-legacy.
(Reading database … 89150 files and directories currently installed.)
Preparing to unpack …/nodejs-legacy_4.2.6~dfsg-1ubuntu4.1_all.deb …
Unpacking nodejs-legacy (4.2.6~dfsg-1ubuntu4.1) …
Processing triggers for man-db (2.7.5-1) …
Setting up nodejs-legacy (4.2.6~dfsg-1ubuntu4.1) …
ubuntu@AWS_TEST: ~]
phantomjs unexpectedly exited. Status code was: 127 が出力された場合
以下のように「phantomjs unexpectedly exited. Status code was: 127」エラーが出力された場合です。
ubuntu@AWS_TEST: ~/dl] python3.6 scrape2.py
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/phantomjs/webdriver.py:49: 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 ‘
Traceback (most recent call last):
File “scrape2.py”, line 5, in
driver = webdriver.PhantomJS(executable_path=’/usr/local/bin/phantomjs’)
File “/usr/local/lib/python3.6/dist-packages/selenium/webdriver/phantomjs/webdriver.py”, line 56, in __init__
self.service.start()
File “/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py”, line 98, in start
self.assert_process_still_running()
File “/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py”, line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/local/bin/phantomjs unexpectedly exited. Status code was: 127
Error in sys.excepthook:
Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/apport_python_hook.py”, line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File “/usr/lib/python3/dist-packages/apport/__init__.py”, line 5, in
from apport.report import Report
File “/usr/lib/python3/dist-packages/apport/report.py”, line 30, in
import apport.fileutils
File “/usr/lib/python3/dist-packages/apport/fileutils.py”, line 23, in
from apport.packaging_impl import impl as packaging
File “/usr/lib/python3/dist-packages/apport/packaging_impl.py”, line 23, in
import apt
File “/usr/lib/python3/dist-packages/apt/__init__.py”, line 23, in
import apt_pkg
ModuleNotFoundError: No module named ‘apt_pkg’
Original exception was:
Traceback (most recent call last):
File “scrape2.py”, line 5, in
driver = webdriver.PhantomJS(executable_path=’/usr/local/bin/phantomjs’)
File “/usr/local/lib/python3.6/dist-packages/selenium/webdriver/phantomjs/webdriver.py”, line 56, in __init__
self.service.start()
File “/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py”, line 98, in start
self.assert_process_still_running()
File “/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py”, line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/local/bin/phantomjs unexpectedly exited. Status code was: 127
コメント