WEBスクレイピングをするためのプラグインはたくさんあります。
CakePHP4にも、pythonやLaravelと同様に、たくさんありますが、
本記事では、もっとも利用方法が簡単で、普及率の高いプラグインである「goutte」のインストール手順を記載しています。
composer実行
1 |
[hogehoge@svxxx]$ composer require fabpot/goutte |
実行結果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2.0 is about to be released and the older 1.x releases will self-update directly to it once it is released. To avoid surprises update now to the latest 1.x version which will prompt you before self-updating to 2.x. Using version ^4.0 for fabpot/goutte ./composer.json has been updated Loading composer repositories with package information Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2.0 is about to be released and the older 1.x releases will self-update directly to it once it is released. To avoid surprises update now to the latest 1.x version which will prompt you before self-updating to 2.x. Updating dependencies (including require-dev) Package operations: 9 installs, 0 updates, 0 removals - Installing symfony/polyfill-php72 (v1.20.0): Downloading (100%) - Installing symfony/polyfill-intl-idn (v1.20.0): Downloading (100%) - Installing symfony/mime (v5.1.7): Loading from cache - Installing symfony/http-client-contracts (v2.3.1): Loading from cache - Installing symfony/http-client (v5.1.7): Downloading (100%) - Installing symfony/dom-crawler (v5.1.7): Loading from cache - Installing symfony/css-selector (v5.1.7): Loading from cache - Installing symfony/browser-kit (v5.1.7): Loading from cache - Installing fabpot/goutte (v4.0.1): Downloading (100%) Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested. Writing lock file Generating autoload files > Cake\Composer\Installer\PluginInstaller::postAutoloadDump |
以上で、goutteのインストールは完了します。
簡単にインストールできて、すぐにスクレイピングを実装できると思います。