私は画像リンクとhrefを見つける必要があります。 show href、img src、およびaltタグ。xpathを使用してextrafをhref、src、altを解析する方法
は、ここに私のコード
$xpath = new DOMXPath('http,://.....');
foreach ($xpath->query('//a[@href]//img') as $img) {
echo '<a href=' .'"' .$img['href'] .'"' .'/>' .'<img src="' .$img['src'] .'"' .'alt="' .$img['alt'] .'"/>' .'</a>';
Catchable fatal error: Argument 1 passed to DOMXPath::__construct() must be an
instance of DOMDocument, string given, called in
あなたは私を助けることはできますか?
負荷 ' DOMDocument'を実行してから、DOMXpathを使用して直接URLをダンプすることはできません – Ghost
参考までに:[PHPでHTML/XMLをどのように解析して処理しますか?](ht tp://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – FirstOne