gpt4 book ai didi

php - HTML 标签之间内容的 XPath 查询

转载 作者:行者123 更新时间:2023-12-02 02:01:29 24 4
gpt4 key购买 nike

我有这样的 HTML:

<html>
<head>
<meta content="{{find_this}}" />
</head>
<body>
<div>{{find_this}}</div>
<span>{{find_this}}</span>
<p>{{find_this}}</p>
</body>
</html>

我将其加载到 DOM 文档和 XPath 中,如下所示:

$dom = new DOMDocument();
$dom->loadHTML($template);
$xpath = new DOMXPath($dom);

我想使用 xpath 查询具有 {{find_this}} 作为值且 no 作为属性值的标记。我怎样才能做到这一点?

最佳答案

这个 XPath 表达式,

//*[.='{{find_this}}']

将选择字符串值等于 {{find_this}}的所有元素(不是属性)。

或者,如果您希望选择字符串值包含字符串的所有元素,请使用以下 XPath:

//*[contains(.,'{{find_this}}')]

关于php - HTML 标签之间内容的 XPath 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37952871/

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