phpでスクレイピングをし、
スクリーンショットを保存するコードを作りたいです。
https://www.genius-web.co.jp/blog/cat-119/selenium_+implementation.html
こちらのサイトを参考に以下コードで実行いたしましたが、
PHP Fatal error: Uncaught Facebook\WebDriver\Exception\WebDriverException: JSON decoding of remote response failed.
というエラーが発生しております。
Seleniumの仕組みをいまいちわかっていないこともあり、
原因が思いつかないのですがわかる方いらっしゃいますでしょうか、
OS:CentOS7
ブラウザ:GoogleChrome(ver75.0.3770.90)
インストールしたもの
・PHP 7.1.30
・GoogleChrome(ver75.0.3770.90)
・chromedriver(75.0.3770.90)
・Selenium-server
・php-webdriver
以下のtest.phpはドキュメントルートにあり、
インストールした各ツールは/usr/local/bin配下にあります。
<?php require '/usr/local/bin/vendor/autoload.php'; use Facebook\WebDriver\Chrome\ChromeOptions; use Facebook\WebDriver\Remote\DesiredCapabilities; use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\WebDriverBy; use Facebook\WebDriver\WebDriverExpectedCondition; $options = new ChromeOptions(); $options->addArguments(['--headless']); $host = 'http://localhost:80'; $capabilities = Facebook\WebDriver\Remote\DesiredCapabilities::chrome(); $capabilities->setCapability(ChromeOptions::CAPABILITY, $options); $driver = Facebook\WebDriver\Remote\RemoteWebDriver::create($host, $capabilities); $driver->get('https://www.google.co.jp/'); $browserLogs = $driver->manage()->getLog('browser'); $element = $driver->findElement(WebDriverBy::name('q')); $element->sendKeys('php スクレイピング'); $element->submit(); $driver->wait(15)->until( WebDriverExpectedCondition::titleIs('php スクレイピング - Google 検索') ); if ($driver->getTitle() !== 'php スクレイピング - Google 検索') { throw new Exception('fail'); } $file = "サンプル_chrome.png"; $driver->takeScreenshot($file); $driver->close();
上記実行をすると以下エラーが発生いたします
PHP Fatal error: Uncaught Facebook\WebDriver\Exception\WebDriverException: JSON decoding of remote response failed. Error code: 4 The response: '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>Not Found</h1> <p>The requested URL /session was not found on this server.</p> </body></html>' in /usr/local/bin/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:298 Stack trace: #0 /usr/local/bin/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php(126): Facebook\WebDriver\Remote\HttpCommandExecutor->execute(Object(Facebook\WebDriver\Remote\WebDriverCommand)) #1 /var/www/html/test.php(14): Facebook\WebDriver\Remote\RemoteWebDriver::create('http://localhos...', Object(Facebook\WebDriver\Remote\DesiredCapabilities)) #2 {main} thrown in /usr/local/bin/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php on line 298
何卒よろしくお願いいたします。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。