Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/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
Php 简单XPath谓词不起作用_Php_Xpath_Web Scraping - Fatal编程技术网

Php 简单XPath谓词不起作用

Php 简单XPath谓词不起作用,php,xpath,web-scraping,Php,Xpath,Web Scraping,我正在运行下面的PHP代码段,该代码段针对HTML页面的源代码计算XPath查询。这个查询似乎是正确的,我用一些在线XPath测试人员对其进行了测试,但没有找到任何匹配项 <?php $details = new DOMDocument(); @$details->loadHTMLFile('http://www.astagiudiziaria.com/beni/lotto_unico_genova_via_della_pigna_6b_-_proc_n_583_14_trib_di

我正在运行下面的PHP代码段,该代码段针对HTML页面的源代码计算XPath查询。这个查询似乎是正确的,我用一些在线XPath测试人员对其进行了测试,但没有找到任何匹配项

<?php
$details = new DOMDocument();
@$details->loadHTMLFile('http://www.astagiudiziaria.com/beni/lotto_unico_genova_via_della_pigna_6b_-_proc_n_583_14_trib_di_genova/index.html');
$xpath = new DOMXpath($details);
$procedimento = $xpath->query('.//ul[preceding-sibling::h2="Informazioni sulla procedura"]/li[(starts-with(., "R.G.E. N°") or starts-with(., "N°")) and not(starts-with(., "N° IVG"))]');
echo $procedimento->length; // returns 0, expected 1
?>

我忘了检查源代码中是否包含空格。这项工作:

.//ul[preceding-sibling::h2="Informazioni sulla procedura"]/li[(starts-with(normalize-space(.), "R.G.E. N°") or starts-with(normalize-space(.), "N°")) and not(starts-with(normalize-space(.), "N° IVG: "))]

我忘了检查源中是否包含空格。这项工作:

.//ul[preceding-sibling::h2="Informazioni sulla procedura"]/li[(starts-with(normalize-space(.), "R.G.E. N°") or starts-with(normalize-space(.), "N°")) and not(starts-with(normalize-space(.), "N° IVG: "))]

恭喜你自己找到了解决办法。如果你还不知道,你也可以。祝贺你自己找到了解决办法。如果你还不知道,你也可以。