【发布时间】:2020-01-13 06:24:55
【问题描述】:
以下是用 PHP 函数编写的代码。现在我正在获取整个 HTML 的所有 img src。我只想拥有整个html的img标签,除了标题中存在的标签。
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
$doc = new DOMDocument();
@$doc->loadHTML($data);
$finder = new DomXPath($doc);
$nodes_images = $finder->query("//img/@src");
【问题讨论】:
标签: html parsing xpath html-parsing xquery