我为汽车网站创建了一个刮板,首先我想获取所有制造商,然后是每个制造商的所有模型链接,但使用下面的代码,我只获得列表中的第一个模型。为什么?
<?php
$dom = new DOMDocument();
@$dom->loadHTMLFile('http://www.auto-types.com');
$xpath = new DOMXPath($dom);
$entries = $xpath->query("//li[@class='clearfix_center']/a/@href");
$output = array();
foreach($entries as $e) {
$dom2 = new DOMDocument();
@$dom2->loadHTMLFile('http://www.auto-types.com' . $e->textContent);
$xpath2 = new DOMXPath($dom2);
$data = array();
$data['newLinks'] = trim($xpath2->query("//div[@class='modelImage']/a/@href")->item(0)->textContent);
$output[] = $data;
}
echo '<pre>' . print_r($output, true) . '</pre>';
?>
所以我需要得到: mercedes/100, mercedes/200, mercedes/300 但现在我的脚本只得到第一个链接,所以 mercedes/100...
请帮忙