function parseProduct($mysqli,$start,$end)
{
$products = $mysqli->query( "SELECT * FROM categories WHERE Parent_sub_ID = 7 " );
foreach ($products as $tovar) {
$product_Url = 'http://happygifts.ru' . $tovar['url'];
parsePagination( $product_Url,$mysqli,$start,$end );
}
}
function parsePagination($url,$mysqli,$start,$end)
{
if ($start < $end){
$fileProduct = file_get_contents( $url );
$value = phpQuery::newDocument( $fileProduct );
$products = $value->find( '.art_n_heading_wp' );
foreach ($products as $product) {
$productpq = pq( $product );
$nameProduct = $productpq->find( '.product-title' )->text();
$artProduct = $productpq->find( '.product-number' )->text();
$slovo1 = strtok( $artProduct, " " );
$slovo2 = strtok( " " );
$mysqli->query( "INSERT INTO tovar (name,art) VALUES ('" . $nameProduct . "','" . $slovo2 . "')" );
}
$next = $value->find( '.catalog-pagination span.modern-page-first ' )->next()->attr( 'href' );
$nexts = 'http://happygifts.ru'.$next;
if (!empty($nexts)) {
$start++;
parsePagination( $nexts,$mysqli,$start,$end );
}
}
}
$start = 0;
$end = 3;
parseProduct($mysqli,$start,$end);
parsePagination($url,$mysqli,$start,$end);