simple_html_dom
私はfind()
ページ上の特定の要素を見つけるためにメソッドを使用しています。ただし、その要素 ( div
) はオプションです。持っているページもあれば、持っていないページもあります。したがって、find()
メソッドが存在しない div を見つけようとすると、すべてのスクリプトがクラッシュします。その行で停止します。どうすれば対処できますかfind()
私はそれを次のように使用しています
....
....
$html = file_get_html($requestUrl);
$result = $html->find("div[id=searchCategoryContainer] ul li")); //problem is here
.... I cant reach these lines if above div is not existed....
....
....
また、try - catch ブロックを使用しようとしましたが、それでも機能しません。
try{
$html = file_get_html($requestUrl);
$result = $html->find("div[id=searchCategoryContainer] ul li"));
throw new Exception("there is no element like this!!!");
}catch(Exception $e){
echo $e->getMessage();
}