function getClasses($ul, $parent = null) { global $count_success; //$nodes = $ul->getElementsByTagName('ul'); //$parent_node = $ul; $li = $ul->firstChild; $count = 0; while ($li) { $link = $li->getElementsByTagName('a'); $span = $link->item(0)->getElementsByTagName('span'); $cat_name = $span->item(0)->nodeValue; $ulnode = $li->getElementsByTagName('ul'); //$ulnode = $ulnode->item(0); cat_to_csv($parent, $cat_name); if ($ulnode->length > 0) { //echo $parent.' '.$cat_name.' '.$ulnode->length.'<br />'; $depth = $ulnode->item(0)->getElementsByTagName('ul'); for ($i = 0; $i < $ulnode->length; $i++) { if ($ulnode->item($i)->getElementsByTagName('ul')->length === $depth->length) { getClasses($ulnode->item($i), $cat_name); $depth = $ulnode->item($i)->getElementsByTagName('ul'); } } } else { //echo $parent.' e '.$cat_name.'<br />'; $enlace = $link->item(0)->getAttribute('href'); $enlace = substr_replace($enlace, 's', 4, 0); file_put_contents("../file/cats_list.ccd", $enlace . PHP_EOL, FILE_APPEND); //var_dump($li->parentNode); echo $enlace . '<br />'; } $li = $li->nextSibling; $count_success++; } }
function getClasses($menu, $parent = null) { global $count_success; //$nodes = $ul->getElementsByTagName('ul'); $base_url = 'http://www.marcapl.com/marca/'; $div = $menu->firstChild; $count = 0; while ($div) { if ($div->nodeType !== 1) { $div = $div->nextSibling; continue; } $name = $div->getElementsByTagName('div'); $parent = $name->item(0)->nodeValue; $ulnode = $div->getElementsByTagName('li'); //$ulnode = $ulnode->item(0); // if ($ulnode->length >= 0) { //echo $parent.' '.$cat_name.' '.$ulnode->length.'<br />'; foreach ($ulnode as $li) { # code... $link = $li->getElementsByTagName('a'); $enlace = $link->item(0)->getAttribute('href'); $cat_name = $link->item(0)->nodeValue; $cat_name = str_replace(PHP_EOL, "", $cat_name); echo $cat_name . ' ' . $parent . '<br />'; cat_to_csv($parent, $cat_name); file_put_contents("../file/cats_list.ccd", $base_url . str_replace(" ", "%20", $enlace) . PHP_EOL, FILE_APPEND); //file_put_contents("../file/cats_list.ccd","coño".PHP_EOL, FILE_APPEND); //var_dump($li->parentNode); echo $base_url . $enlace . '<br />'; } } $div = $div->nextSibling; $count_success++; } }