Php 简单XPath谓词不起作用
我正在运行下面的PHP代码段,该代码段针对HTML页面的源代码计算XPath查询。这个查询似乎是正确的,我用一些在线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
$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: "))]
恭喜你自己找到了解决办法。如果你还不知道,你也可以。祝贺你自己找到了解决办法。如果你还不知道,你也可以。