function getAllSubCategories($filename)
{
$categories = unserialize(file_get_contents($filename));
echo "---- run getAllSubCategories() ----\n\r";
foreach ($categories as $j => $category) {
if ($category['childrens']) {
foreach ($category['childrens'] as $k => $children) {
echo "---- crawling childrens for {$children['name']} ----\n\r";
$doc = phpQuery::newDocumentHTML(fetch('http://www.walmart.com' . $children['link']));
phpQuery::selectDocument($doc);
foreach (pq('.shop-by-category li') as $el) {
echo "---- " . pq($el)->find('a')->attr('href') . "} ----\n\r";
$childrens[] = array('name' => pq($el)->find('a')->data('name'), 'link' => pq($el)->find('a')->attr('href'));
}
$categories[$j]['childrens'][$k]['childrens'] = $childrens;
}
}
}
echo "---- creating deparment file ----\n\r";
$file = fopen($filename, 'w+');
echo "---- writing deparment file ----\n\r";
fputs($file, serialize($categories));
echo "---- closing deparment file ----\n\r";
fclose($file);
}