Advertisement
Guest User

Parser

a guest
Mar 11th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Document</title>
  6. </head>
  7. <body>
  8. <?php
  9.     include 'simple_html_dom.php';
  10.     $db = mysqli_connect('localhost', 'mysql', 'mysql', 'sshmarket');
  11.     if (mysqli_connect_errno()) {
  12.         printf("Connection error: %s\n", mysqli_connect_error());
  13.         exit();
  14.     }
  15.  
  16.     $site = 'http://optnow.ru/catalog';
  17.     $data = file_get_html($site);
  18.     $catalogLink = array();
  19.     $i = 0;
  20.     if(!empty($data)) {
  21.         foreach($data->find('div.cat-name a') as $catalog) {
  22.             $catalogLink['url'] = $catalog->href;
  23.             $urls[] = $catalogLink;
  24.         }
  25.         foreach($urls as $url => $k) {
  26.             foreach($k as $n) {
  27.                 $catalogLink = 'http://optnow.ru/' . $n . '?page=0';
  28.                 $productData = file_get_html($catalogLink);
  29.                 foreach($productData->find('.link-pv-name') as $link) {
  30.                     $productLink['url'] = $link->href;
  31.                     $productUrls[] = $productLink;
  32.                 }
  33.  
  34.             foreach($productUrls as $href) {
  35.                 $link = 'http://optnow.ru/' . $href['url'];
  36.                     $product = file_get_html($link);
  37.                     foreach($product->find('.block-d .btns-d .btn-buy') as $productId) {
  38.                         if(!empty($productId)) {
  39.                             $dataId = $productId->{'data-offerid'};
  40.                             print_r($dataId);
  41.                         }
  42.                     }
  43.                     foreach($product->find('.description div div p') as $description) {
  44.                         if(!empty($description)) {
  45.                             $query = "UPDATE snowcore_parser_products SET description = '0' WHERE remote_id = " . $dataId . " ';";
  46.                             $sql = mysqli_query($db, $query);
  47.                             print_r($sql);
  48.                         }
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.     }
  54. ?>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement