我有两个Xpath请求:
$was_price_location = "//ul[@id='items']/li/div[@class='productprice']/span[@class='price' or @class='recRP rrp']";
$now_price_location = "//ul[@id='items']/li/div[@class='productprice']/span[@class='prevPrice previousprice' or @class='price outlet-current-price']";
但是,我想修改它,以便只返回指定不为空的节点。
目前,它发现多余的<span class="recRP rrp">
和<span class="prevPrice previousprice">
个节点是空的,因此与我无关。
答案 0 :(得分:0)
这应该有效:
$prod_price_location = "//ul[@id='items']/li/div[@class='productprice']";
$was_price_location = $prod_price_location .
"/span[@class='price' or @class='recRP rrp'][normalize-space()]";
$now_price_location = $prod_price_location .
"/span[@class='prevPrice previousprice' or @class='price outlet-current-price']" .
"[normalize-space()]";