From 475c200b67e2d82ca8b10f42ecd93c817dc5caf4 Mon Sep 17 00:00:00 2001 From: krzysiej Date: Mon, 30 May 2022 11:54:32 +0200 Subject: [PATCH] Before running parse operation on search results page it checks now if there are any books to parse. --- src/DataParser.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/DataParser.php b/src/DataParser.php index 53d92a9..189113d 100644 --- a/src/DataParser.php +++ b/src/DataParser.php @@ -49,13 +49,15 @@ class DataParser $books = $document->find('#search .authorAllBooks__single'); $booksInfo = []; - foreach ($books as $book) { - $bookInfo = new Info(); - $bookInfo->title = trim($book->first('.authorAllBooks__singleTextTitle')->text()); - $bookInfo->author = trim($book->first('.authorAllBooks__singleTextAuthor')->text()); - $bookInfo->url = $book->first('button[data-book-url]')->getAttribute('data-book-url'); - $bookInfo->cover_url = $this->generateCoverUrls($book->first('.img-fluid')->getAttribute('data-src')); - $booksInfo[] = $bookInfo; + if ($document->has('#searchksiazki')) { + foreach ($books as $book) { + $bookInfo = new Info(); + $bookInfo->title = trim($book->first('.authorAllBooks__singleTextTitle')->text()); + $bookInfo->author = trim($book->first('.authorAllBooks__singleTextAuthor')->text()); + $bookInfo->url = $book->first('button[data-book-url]')->getAttribute('data-book-url'); + $bookInfo->cover_url = $this->generateCoverUrls($book->first('.img-fluid')->getAttribute('data-src')); + $booksInfo[] = $bookInfo; + } } return $booksInfo; }