在这里,我有一些脚本,但是 3 个 foreach 函数太长了,并且出现了内部服务器错误。我可以用 curl 或类似的东西解决这个问题吗?
这是代码:
<?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();
$items = $xpath2->query("//div[@class='modelImage']/a/@href");
$links = array();
foreach($items as $item) {
$dom3 = new DOMDocument();
@$dom3->loadHTMLFile('http://www.auto-types.com' . $item->textContent);
$xpath3 = new DOMXpath($dom3);
$konacno = array();
$krajs = $xpath3->query("//div/@onclick");
foreach ($krajs as $kraj) {
$konacno[] = $kraj->textContent;
}
}
$data['newLinks'] = implode(', ', $konacno);
$output[] = $data;
}
echo '<pre>' . print_r($output, true) . '</pre>';
?>