【发布时间】:2019-06-13 19:33:40
【问题描述】:
我正在寻找段落中第一句的 Xpath 表达式。
<p>
A federal agency is recommending that White House adviser Kellyanne Conway be
removed from federal service saying she violated the Hatch Act on numerous
occasions. The office is unrelated to Robert Mueller and his investigation.
</p>
结果应该是:
A federal agency is recommending that White House adviser Kellyanne Conway be
removed from federal service saying she violated the Hatch Act on numerous
occasions.
我尝试了一些方法无济于事。
$expression = '/html/body/div/div/div/div/p//text()';
我需要使用://p[ends-with 还是 substring-before?
【问题讨论】:
-
您需要明确您使用的 XPath 版本。这种事情在 XPath 2.0 或更高版本中要容易得多。您指的是
ends-with(),它需要 XPath 2.0,但您也提到 PHP,这表明您仅限于 1.0。
标签: php xml xpath xml-parsing domxpath