我在网上购物。我有网址列表,加载他们,然后抓取表。井。第一页是正确的,它可能有30个参数。接下来的页面有20个参数,在复制它们之前没有来自页面的参数。这就是我的问题:为什么?也许我只是不知道如何清理数组,你能帮我吗?
//The code
foreach($odkazy as $odkaz) {
//Here i am loading each page
$html = new simple_html_dom();
$html->load_file($odkaz);
//Finding code of prodcut
$ptyp = $html->find("span.p-type");
foreach($ptyp as $a)
$item["p-type"] = trim($a->plaintext);
//Here are values of product
$hodnoticky = $html->find("dd");
foreach($hodnoticky as $h)
$hodnota[] = preg_replace('/\s\s+/', ' ',$h->plaintext);
//Here are parameters
$parametrici = $html->find("dt");
foreach($parametrici as $p)
$parametr[] = preg_replace('/\s\s+/', ' ',$p->plaintext);
//Here i am mixing them.
foreach($parametr as $i => $key)
$item[trim($key)] = $hodnota[$i];
$items[] = $item;
$html->clear();
unset($html);
}
print_r($items);
发布于 2018-08-14 03:26:06
看起来项目数组在循环之间永远不会被取消设置。试试这个:
foreach($odkazy as $odkaz) {
// ... rest of your code here
$items[] = $item;
$html->clear();
unset($item); // ADD THIS HERE
unset($html);
}
print_r($items);
发布于 2018-08-14 03:40:23
哦..。谢谢@JacobW。问题出现在另一个数组中。我尝试取消设置$item..但解决方案是取消数组的值和参数。谢谢!
$items[] = $item;
$html->clear();
unset($parametr);
unset($hodnota);
unset($item);
unset($html);
https://stackoverflow.com/questions/51829095
复制相似问题