G
G
ganjo8882018-02-18 18:39:17
PHP
ganjo888, 2018-02-18 18:39:17

How to make pagination parsed using phpquery?

Tell me how to make pagination navigation parsed. The $next variable contains a link to the next page.

function parseProduct($mysqli){
$products = $mysqli->query( "SELECT * FROM categories WHERE Parent_sub_ID > 0  " );

foreach ($products as $tovar) {
    $product_Url = 'http://happygifts.ru' . $tovar['url'];
    $fileProduct = file_get_contents( $product_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 tovars (name,art) VALUES ('" . $nameProduct . "','" . $slovo2 . "')" );
    }
    $next = $value->find( '.catalog-pagination span.modern-page-first ' )->next()->attr( 'href' );
}}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Bobkov, 2018-02-18
@mike_bma

Take the code for parsing the category page into a separate function that accepts
an example url:

foreach ($products as $tovar) {
  $product_Url = 'http://happygifts.ru' . $tovar['url'];
  parseCategory($product_Url)
}

function parseCategory($url){
...//тут парсим продукты страницы
  if($next){
    parseCategory($next);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question