Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foreach ($categories as $category) {
- $url = $category['source_url'];
- $category_id = $category['id'];
- $os = $category['os'];
- try {
- $count = 1;
- while (true) {
- $body = $this->client->get($url . $this->uri . $count)->getBody();
- $this->crawler->addHtmlContent($body);
- $nodes = $this->crawler->filter(".list-app")->children();
- $nodes->each(function ($node) use($category_id, $os){
- $url = $node->filter('a')->attr('href');
- $body = $this->client->get($url)->getBody();
- $this->product_crawler->addHtmlContent($body);
- $title = $this->product_crawler->filter('h1 > span.left.floated')->text();
- Product::updateOrCreate(compact('title', 'category_id', 'os'));
- $this->product_crawler->clear();
- });
- $this->crawler->clear();
- $count++;
- }
- } catch (ClientException $e) {
- return $e->getResponse()->getStatusCode();
- } catch (\InvalidArgumentException $exception) {
- return $exception->getMessage();
- } catch (\Exception $exc) {
- continue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement