Google ColabにおけるPhantomJSの使い方
Google Colabでスクレイピングの練習をしているのですが、以下のコードを動かしても以下のようなエラーが出てしまいます。どのようにPATHを指定すればこの問題は解決するのでしょうか?
コードは https://review-of-my-life.blogspot.com/2017/10/python-web-scraping-data-collection-analysis.html にあったものを参照しています。
!pip install selenium
#trendAnalytics.py
from selenium import webdriver
from pandas import *
import time
#Access to page
browser = webdriver.PhantomJS()
エラー
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 '
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in start(self)
75 stderr=self.log_file,
---> 76 stdin=PIPE)
77 except TypeError:
/usr/lib/python3.6/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
708 errread, errwrite,
--> 709 restore_signals, start_new_session)
710 except:
/usr/lib/python3.6/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1343 err_msg += ': ' + repr(err_filename)
-> 1344 raise child_exception_type(errno_num, err_msg, err_filename)
1345 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'phantomjs': 'phantomjs'
During handling of the above exception, another exception occurred:
WebDriverException Traceback (most recent call last)
<ipython-input-3-3131533f6b12> in <module>()
4
5 #Access to page
----> 6 browser = webdriver.PhantomJS()
7 # DO NOT FORGET to set path
8 url = "http://b.hatena.ne.jp/search/text?safe=on&q=Python&users=50"
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/phantomjs/webdriver.py in __init__(self, executable_path, port, desired_capabilities, service_args, service_log_path)
54 service_args=service_args,
55 log_path=service_log_path)
---> 56 self.service.start()
57
58 try:
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in start(self)
81 raise WebDriverException(
82 "'%s' executable needs to be in PATH. %s" % (
---> 83 os.path.basename(self.path), self.start_error_message)
84 )
85 elif err.errno == errno.EACCES:
WebDriverException: Message: 'phantomjs' executable needs to be in PATH.