gpt4 book ai didi

PHP XPath,无法检索目标标签内标签后的文本

转载 作者:行者123 更新时间:2023-12-03 02:44:52 25 4
gpt4 key购买 nike

我有这个 html 代码,要在上面执行 xpath:

<b>Random Field:</b>
<p>
A random field describes an <a href="/index.php?page=glossary&term_id=230">
experiment</a> with outcomes being functions of more than one continuous variable,
for example U(x,y,z), where x, y, and z are coordinates in space. Random field is
extension of the concept of <a href="/index.php?page=glossary&term_id=598">random
process</a> into the case of multivariate argument.
</p>

我尝试这样做来获取 <p> 中的文本标签:

$dom = new DomDocument();
$dom->loadHtml($curl_scraped_page);
$xpath = new DomXPath($dom);
print $xpath->evaluate('string(//p[preceding::b]/text())');

但它只是给了我这个:

A random field describes an

我想要的是:

A random field describes an ..(an so on until).. of multivariate argument.所以我猜测问题出在<a>上标签。因为每次我尝试在相同模式的文档上执行此操作时,它都会在此 <a> 之前停止标签。谢谢..

最佳答案

这会起作用:

$xpath->query('//p[preceding::b]')->item(0)->textContent;

XPath 中有一个 string-join 函数,但遗憾的是 PHP 使用的 lbxml 中的 XPath 1.0 版本中没有这个函数。

关于PHP XPath,无法检索目标标签内标签后的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17598942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com