{"id":3302,"date":"2022-06-12T10:33:01","date_gmt":"2022-06-12T01:33:01","guid":{"rendered":"https:\/\/blue-bear.jp\/kb\/?p=3302"},"modified":"2022-06-12T10:54:20","modified_gmt":"2022-06-12T01:54:20","slug":"debian%e3%81%a7seleniumchromedriver%e3%82%92%e5%b0%8e%e5%85%a5%e3%81%97%e3%81%a6%e3%81%b8%e3%81%a3%e3%81%a9%e3%83%ac%e3%82%b9%e3%83%96%e3%83%a9%e3%82%a6%e3%82%b6%e3%82%92php%e3%81%a7%e5%ae%9f","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/debian%e3%81%a7seleniumchromedriver%e3%82%92%e5%b0%8e%e5%85%a5%e3%81%97%e3%81%a6%e3%81%b8%e3%81%a3%e3%81%a9%e3%83%ac%e3%82%b9%e3%83%96%e3%83%a9%e3%82%a6%e3%82%b6%e3%82%92php%e3%81%a7%e5%ae%9f\/","title":{"rendered":"Debian\u3067selenium+chromedriver\u3092\u5c0e\u5165\u3057\u3066\u30d8\u30c3\u30c9\u30ec\u30b9\u30d6\u30e9\u30a6\u30b6\u3092PHP\u3067\u5b9f\u884c\u3059\u308b\u74b0\u5883\u69cb\u7bc9"},"content":{"rendered":"\n<p>Debian (Bitnami WordPress) \u3067selenium+chromedriver\u3092\u5c0e\u5165\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u624b\u9806<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u65e5\u672c\u8a9e\u30d5\u30a9\u30f3\u30c8\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install fonts-takao\nsudo apt-get install fontconfig\nsudo fc-cache -fv\nfc-match TakaoGothic\nsudo apt install fonts-ipafont fonts-ipaexfont\nsudo fc-cache -fv\nfc-match IPAGothic<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">chrome\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u30ad\u30fc\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nwget https:\/\/dl.google.com\/linux\/linux_signing_key.pub\nsudo apt-get -y install gnupg\nsudo apt-key add linux_signing_key.pub\n\n\/\/Chrome\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\necho 'deb &#91;arch=amd64] http:\/\/dl.google.com\/linux\/chrome\/deb\/ stable main' | sudo tee \/etc\/apt\/sources.list.d\/google-chrome.list\nsudo apt-get update\nsudo apt-get install google-chrome-stable\n\n\/\/\u30d0\u30fc\u30b8\u30e7\u30f3\u78ba\u8a8d\ngoogle-chrome --version\n\u4f8b\uff1aGoogle Chrome 102.0.5005.115 <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">chromeDriver\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n\n\n\n<p>\u6ce8\u610f\uff1a\u5148\u7a0b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305fChrome\u3068\u540c\u3058\u30d0\u30fc\u30b8\u30e7\u30f3\u306eDriver\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u3002\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u30e1\u30b8\u30e3\u30fc\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u3042\u3063\u3066\u3044\u308c\u3070\u3088\u3044\u3002\u4f8b\u3067\u306f102\u3092\u9078\u629e<\/p>\n\n\n\n<p><a href=\"https:\/\/chromedriver.chromium.org\/downloads\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/chromedriver.chromium.org\/downloads<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"322\" src=\"https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-1024x322.png\" alt=\"\" class=\"wp-image-3303\" srcset=\"https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-1024x322.png 1024w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-300x94.png 300w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-768x242.png 768w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-1536x483.png 1536w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image.png 1716w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u30c9\u30e9\u30a4\u30d0\u30fc\u306e\u30ea\u30f3\u30af\u3092\u30b3\u30d4\u30fc<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget &#91;\u5148\u7a0b\u30b3\u30d4\u30fc\u3057\u305f\u30c9\u30e9\u30a4\u30d0\u306e\u30ea\u30f3\u30af]\nunzip chromedriver_linux64.zip \nsudo mv chromedriver \/usr\/local\/bin\/\n\n\/\/\u30d0\u30fc\u30b8\u30e7\u30f3\u78ba\u8a8d\nchromedriver --version\n\u4f8b\uff1aChromeDriver 102.0.5005.61 (0e59bcc00cc4985ce39ad31c150065f159d95ad3-refs\/branch-heads\/5005@{#819})<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Selenium\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.selenium.dev\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.selenium.dev\/downloads\/<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"428\" src=\"https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-1-1024x428.png\" alt=\"\" class=\"wp-image-3304\" srcset=\"https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-1-1024x428.png 1024w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-1-300x125.png 300w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-1-768x321.png 768w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-1-1536x642.png 1536w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-1-2048x856.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Stable\u306e\u30ea\u30f3\u30af\u3092\u30b3\u30d4\u30fc<\/p>\n\n\n\n<p>\u4f8b\uff1ahttps:\/\/github.com\/SeleniumHQ\/selenium\/releases\/download\/selenium-4.2.0\/selenium-server-4.2.2.jar<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/github.com\/SeleniumHQ\/selenium\/releases\/download\/selenium-4.2.0\/selenium-server-4.2.2.jar\nsudo cp selenium-server-4.2.2.jar \/usr\/local\/bin\/\n\n\/\/JAVA\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nsudo apt install default-jre\n\n\/\/\u8d77\u52d5\njava -jar \/usr\/local\/bin\/selenium-server-4.2.2.jar &amp;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Composer\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n\n\n\n<p>php-webdriver\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306b\u5fc5\u8981\u306a\u306e\u3067Composer\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -sS https:\/\/getcomposer.org\/installer | php\nsudo mv composer.phar \/usr\/local\/bin\/composer\ncomposer --version<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">php-webdriver\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>cd &#91;php-webdriver\u3092\u5b9f\u884c\u3055\u305b\u305f\u3044Path\uff1dVendor\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\u3057\u305f\u3044Path]\ncomposer require php-webdriver\/webdriver<\/code><\/pre>\n\n\n\n<p>\u52d5\u4f5c\u78ba\u8a8d\u30b5\u30f3\u30d7\u30eb<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi .\/sample.php\n\n\/\/\u4e0b\u8a18\u30b3\u30fc\u30c9\u3092\u8cbc\u308a\u4ed8\u3051\n&lt;?php\nrequire_once __DIR__ . '\/vendor\/autoload.php';\nuse Facebook\\WebDriver\\Chrome\\ChromeOptions;\nuse Facebook\\WebDriver\\Chrome\\ChromeDriver;\nuse Facebook\\WebDriver\\Remote\\DesiredCapabilities;\nuse Facebook\\WebDriver\\Remote\\RemoteWebDriver;\nuse Facebook\\WebDriver\\WebDriverExpectedCondition;\nuse Facebook\\WebDriver\\WebDriverBy;\n\n$driverPath = realpath(\"\/usr\/local\/bin\/chromedriver\");\nputenv(\"webdriver.chrome.driver=\" . $driverPath);\n\n\/\/ chrome option\n$options = new ChromeOptions();\n$options->addArguments(&#91;\n    'disable-infobars',\n    '--headless',\n    \/\/'start-maximized',\n    'window-size=1920,1600',\n]);\n\n$capabilitites = DesiredCapabilities::chrome();\n$capabilitites->setCapability(ChromeOptions::CAPABILITY, $options);\n$driver = ChromeDriver::start($capabilitites);\n\n\/\/ google\u306e\u30da\u30fc\u30b8\u53d6\u5f97\n$driver->get('https:\/\/www.google.co.jp\/');\n\/\/ \u8868\u793a\u3055\u308c\u308b\u307e\u3067\u5f85\u3064\n$driver->wait(2)->until(\n    WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::name('q'))\n);\n\n\/\/ \u30ad\u30e3\u30d7\u30c1\u30e3\u3092\u3068\u308b\n$file = \".\/sample.png\";\n$driver->takeScreenshot($file);\n\n\/\/ \u30d6\u30e9\u30a6\u30b6\u3092\u9589\u3058\u308b\n$driver->quit();<\/code><\/pre>\n\n\n\n<p>PHP\u30d5\u30a1\u30a4\u30eb\u3092\u5b9f\u884c\u3057\u3066\u30ad\u30e3\u30d7\u30c1\u30e3\u304c\u53d6\u308c\u3066\u3044\u308c\u3070\u6210\u529f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php sample.php<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-2.png\" alt=\"\" class=\"wp-image-3305\" width=\"450\" height=\"219\" srcset=\"https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-2.png 806w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-2-300x146.png 300w, https:\/\/blue-bear.jp\/kb\/wp-content\/uploads\/2022\/06\/image-2-768x374.png 768w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><figcaption>sample.png<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067chromedriver\u3092\u8d77\u52d5<\/h2>\n\n\n\n<p>\u5f85\u53d7\u30dd\u30fc\u30c8\u306f4444\u3092\u6307\u5b9a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nohup \/usr\/local\/bin\/chromedriver -port=4444 &amp;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u81ea\u52d5\u8d77\u52d5\u8a2d\u5b9a<\/h2>\n\n\n\n<p>\u3053\u306e\u307e\u307e\u3060\u3068\u30b5\u30fc\u30d0\u3092reboot\u3059\u308b\u3068ChromeDriver\u304c\u81ea\u52d5\u8d77\u52d5\u3057\u306a\u3044\u306e\u3067\u3001cron\u3067\u81ea\u52d5\u8d77\u52d5\u8a2d\u5b9a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi chrome-autorun.sh\n\n\/\/\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8cbc\u308a\u4ed8\u3051\n#!\/bin\/bash\nnohup \/usr\/local\/bin\/chromedriver -port=4444 &amp;<\/code><\/pre>\n\n\n\n<p>Crontab\u3067reboot\u8ffd\u8a18<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>crontab -e\n\n\/\/\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u8a18\n@reboot \/home\/bitnami\/chrome-autorun.sh<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Debian (Bitnami Word<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[243,461,456,460,462],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3302"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=3302"}],"version-history":[{"count":4,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3302\/revisions"}],"predecessor-version":[{"id":3312,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3302\/revisions\/3312"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=3302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=3302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=3302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}