我如何使用以下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";
}
答案 0 :(得分:2)
你想要一个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>
答案 1 :(得分:1)
您可以使用给定的xpath
/div[@class="book"]/span[@class="price"]/text()