gpt4 book ai didi

php - 使用 xPath 获取价格(使用大于)

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

如何使用以下 xPath 示例:

//book[price>35.00]

这样(因为美元符号是静态的):

<div class="book"><span class="price">$35</span></div>

<强>------------------从答案编辑------------------

    $vu_link = get_field('vu_link');

$ch3 = curl_init($vu_link);
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true);
$cl3 = curl_exec($ch3);

$dom3 = new DOMDocument();
@$dom3->loadHTML($cl3);
$xpath3 = new DOMXpath($dom3);

$price3 = $xpath3->query("//div[@class = 'price-box' and substring(span[@class = 'price'], 2) > 100]");

foreach ($xpath->query($price3) as $node) {
echo $dom->saveXML($node), "\n";
}

最佳答案

您需要一个类似于以下内容的 xpath 表达式:

//div[@class = 'book' and substring(span[@class = 'price'], 2) > 35]

<小时/>

示例:

$xml = <<<'XML'
<root>
<div class="book"><span class="price">$35</span></div>
<div class="book"><span class="price">$34</span></div>
<div class="book"><span class="price">$33</span></div>
<div class="book"><span class="price">$36</span></div>
</root>
XML;

$dom = new DOMDocument();
$dom->loadXML($xml);
$xpath = new DOMXPath($dom);

$query = "//div[@class = 'book' and substring(span[@class = 'price'], 2) > 35]";

foreach ($xpath->query($query) as $node) {
echo $dom->saveXML($node), "\n";
}
<小时/>

输出:

<div class="book"><span class="price">$36</span></div>

关于php - 使用 xPath 获取价格(使用大于),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27835592/

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