Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. foreach ($categories as $category) {
  2.             $url = $category['source_url'];
  3.             $category_id = $category['id'];
  4.             $os = $category['os'];
  5.  
  6.             try {
  7.                 $count = 1;
  8.                 while (true) {
  9.                     $body = $this->client->get($url . $this->uri . $count)->getBody();
  10.                     $this->crawler->addHtmlContent($body);
  11.                     $nodes = $this->crawler->filter(".list-app")->children();
  12.  
  13.                     $nodes->each(function ($node) use($category_id, $os){
  14.                         $url = $node->filter('a')->attr('href');
  15.  
  16.                         $body = $this->client->get($url)->getBody();
  17.                         $this->product_crawler->addHtmlContent($body);
  18.                         $title = $this->product_crawler->filter('h1 > span.left.floated')->text();
  19.                         Product::updateOrCreate(compact('title', 'category_id', 'os'));
  20.                         $this->product_crawler->clear();
  21.  
  22.                     });
  23.  
  24.                     $this->crawler->clear();
  25.                     $count++;
  26.                 }
  27.             } catch (ClientException $e) {
  28.                 return $e->getResponse()->getStatusCode();
  29.             } catch (\InvalidArgumentException $exception) {
  30.                 return $exception->getMessage();
  31.             } catch (\Exception $exc) {
  32.                 continue;
  33.             }
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement