0
昨天晚上的类似问题,我无法编辑源HTML,我试图解析网站上的大量数据来对产品进行价格/比较。大多数情况下,它正在工作,但我现在正在努力让它更高效,更快速,更轻松地阅读我的意大利面代码。PHP Xpath,帮助选择一个非常特定的节点
我有以下测试代码;我想要做的只是返回内容的属性(例如thisiswhatiwant)if productType的nodeValue被存储,没有别的。
<div id="productListing">
<div class="productDetail">
<span class="productType">Stocked</span>: <span class="productStock"><span class='productContent' content='thisiswhatiwant'></span></span>
</div>
<div class="productDetail">
<span class="productType">Non-stocked</span>: <span class="productStock"><span class='productContent' content='xyz'></span></span>
</div>
…
<div class="productDetail">
<span class="productType">Non-stocked</span>: <span class="productStock"><span class='productContent' content='123'></span></span>
</div>
</div>
这是XPath查询我有这么远,但我是丢失在我的大脑至关重要的东西或东西只是没有点击进入齿轮呢。
//div[@id="productListing"]/div[@class="productDetail"]/span[@class="productStock"]/preceding-sibling::span[text()="Stocked"]
基本上,我想从上面的测试代码的输出是:
<?
echo "Output: " . $dom->getAttribute('content');
?>
Output: thisiswhatiwant
任何人有什么想法?
这做到了!谢谢。 – 2010-05-17 12:23:51