【Selenium】facebook/php-webdriverでスクレイピングする方法メモ
centosでseleniumでやる方法探してたらまさにやりたいことがこのページにまるまる載ってました。助かりました。ありがとうございます。
php-webdriverを使用してスクレイピングをした話 - 備忘録
ほぼこのとおりにやったらいけました。
一部ちがったところと動かなかったところをメモしておく。
最終的な各種バージョン
# CentOSのバージョン $ cat /etc/redhat-release CentOS release 6.8 (Final) # Firefoxのバージョン $ firefox -v Mozilla Firefox 45.7.0 # JAVAのバージョン $ java -version openjdk version "1.8.0_121" OpenJDK Runtime Environment (build 1.8.0_121-b13) OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode) # seleniumのバージョン selenium-server-standalone-2.53.0.jar
firefoxのバージョンは新し目だけど動いてるみたい。
3ヶ月経ってるから解消したのかな。
php実行でエラー
で、php実行したら以下のエラーが出た。
$ php test.php 01:42:41.927 WARN - Exception: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: tionsType":null,"aboutURL":null,"icons":{},"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Japanese Language Pack","description":null,"creator":"Mozilla Japanese L10N Community","homepageURL":null,"con$ ・・・ process 6990: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/var/lib/dbus/machine-id": そのようなファイルやディレクトリはありません See the manual page for dbus-uuidgen to correct this issue. D-Bus not built with -rdynamic so unable to print a backtrace Redirecting call to abort() to mozalloc_abort
「"/var/lib/dbus/machine-id": そのようなファイルやディレクトリはありません」って。
rootユーザーで作ったらいけた
# dbus-uuidgen > /var/lib/dbus/machine-id
以下、メモ
セットアップ
$ wget http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar $ yum -y install java-1.8.0-openjdk $ yum -y install xorg-x11-server-Xvfb $ yum -y install firefox # ここ怪しい
起動時のコマンド
$ export DISPLAY=:99 $ Xvfb :99 -screen 0 1024x768x24 & $ java -jar /path/to/selenium-server-standalone-2.53.0.jar
以上です。