让我们说我要删除此代码(请记住,文章包含在其他代码中):
<article class="offer-item">
<h3>A Title</h3>
<a href="#">
<span class="offer-item-title">Content that I want</span>
</a>
</article>
我有以下代码用于废弃上述代码:
$dom = new DomDocument;
$dom->loadHTMLFile("URL");
$xpath = new DomXPath($dom);
$listing_url = $xpath->query("//article[@class='offer-item']//span[@class='offer-item-title']");
但它不起作用,事实上我知道这是因为文章标签。因为如果我将它删除并保留它就可以了:
$listing_url = $xpath->query("//span[@class='offer-item-title']");
感谢能帮助我的人!真的很感激!