Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我正在解析html,我不想包含header元素的header-img标记_Html_Parsing_Xpath_Html Parsing_Xquery - Fatal编程技术网

我正在解析html,我不想包含header元素的header-img标记

我正在解析html,我不想包含header元素的header-img标记,html,parsing,xpath,html-parsing,xquery,Html,Parsing,Xpath,Html Parsing,Xquery,下面是用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); $da

下面是用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");

如果您引用的是HTML5
元素,那么使用
//img[not(祖先::头)]/@src
应该选择所有
img
元素的所有
src
属性,这些元素不是
元素的后代。然而,我不知道PHP的loadHTML使用的基于libxml2的HTML解析对解析HTML5的支持有多好。

我想获得HTML的所有img标记的src,元素中存在的标记除外。标题包括菜单、徽标和社交媒体图标。