LoginSignup
7
8

More than 5 years have passed since last update.

Goutte の filter で対象の有無をチェック

Posted at

Goutte を使っている時に、filter対象のタグの有無を確認したい場合があったりします。
ない場合に ->text() とか使おうとすると例外が投げられます。

exists とか無いかなと思っていたけど無いみたいなのですが、
count() を使えば存在確認は出来るみたいです。

$div_target = $crawler->filter('div.target');
if ($div_target->count()) {
    print('exists');
} else {
    print('not exists');
}

なかなか見つからなかったのでメモメモ。

7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8