サイトアイコン Dev-Dev

【PHP】Goutte を使ったスクレイピング

【PHP】Goutte を使ったスクレイピング

↓こちらのサイトを参考にして、Goutte を使ったスクレイピング をしてみました。

Goutte めも - tatenosystem.com

インストール

利用するディレクトリにインストール

composer require fabpot/goutte

サンプルコード

<?php
//ライブラリロード
require_once './vendor/autoload.php';
//use
use Goutte\Client;
//インスタンス生成
$client = new Client();
//取得とDOM構築
$crawler = $client->request('GET','http://localhost/test/test.html');
//要素の取得
$tr = $crawler->filter('a')->each(function($element){
echo $element->attr('href');
});
モバイルバージョンを終了