我在这里有一个 HTML 块:
<div class="title">
<a href="http://test.com/asus_rt-n53/p195257/">
Asus RT-N53
</a>
</div>
<table>
<tbody>
<tr>
<td class="price-status">
<div class="status">
<span class="available">Yes</span>
</div>
<div name="price" class="price">
<div class="uah">758<span> ua.</span></div>
<div class="usd">$ 62</div>
</div>
如何解析链接 ( http://test.com/asus_rt-n53/p195257/
)、标题 ( Asus RT-N53
) 和价格 ( 758
)?
卷曲代码在这里:
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML($content);
$xpath = new DOMXPath($dom);
$models = $xpath->query('//div[@class="title"]/a');
foreach ($models as $model) {
echo $model->nodeValue;
$prices = $xpath->query('//div[@class="uah"]');
foreach ($prices as $price) {
echo $price->nodeValue;
}
}