Rozpoczęcie pobierania informacji o książce.
This commit is contained in:
31
packt.php
31
packt.php
@@ -44,6 +44,34 @@ function c($url, $post = [])
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getBookInfo($bookUrl)
|
||||||
|
{
|
||||||
|
|
||||||
|
// $bookPage = c($bookUrl);
|
||||||
|
$bookData = [];
|
||||||
|
$bookPage = new Document($bookUrl, true);
|
||||||
|
$bookData['authors'] = $bookPage->find('.book-top-block-info-authors::text');
|
||||||
|
$bookData['datepublished'] = $bookPage->first('.book-top-block-info-authors')->first('time[itemprop="datePublished"]::attr(datetime)');
|
||||||
|
$bookData['numberofpages'] = $bookPage->first('span[itemprop="numberOfPages"]::text');
|
||||||
|
$bookData['isbn'] = $bookPage->first('span[itemprop="isbn"]::text');
|
||||||
|
$bookData['reviewCount'] = $bookPage->first('meta[itemprop="reviewCount"]::attr(content)');
|
||||||
|
$bookData['ratingValue'] = $bookPage->first('meta[itemprop="ratingValue"]::attr(content)');
|
||||||
|
|
||||||
|
$bookData['toc'] = [];
|
||||||
|
foreach ($bookPage->first('#book-info-toc.onlyDesktop')->find('.book-toc-chapter') as $chapter) {
|
||||||
|
if (!is_null($chapter->first('div[class*="book-toc-chapter-title"]'))) {
|
||||||
|
|
||||||
|
$tocSection = [];
|
||||||
|
$tocSection['title'] = trim($chapter->first('div[class*="book-toc-chapter-title"]')->text());
|
||||||
|
$tocSection['subchapters'] = $chapter->find('div[class*="book-toc-section-text"]::text');
|
||||||
|
$bookData['toc'][] = $tocSection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bookData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//$return = c('https://www.packtpub.com/', $loginData);
|
//$return = c('https://www.packtpub.com/', $loginData);
|
||||||
//$return = c('https://www.packtpub.com/account/my-ebooks');
|
//$return = c('https://www.packtpub.com/account/my-ebooks');
|
||||||
//var_dump($return);
|
//var_dump($return);
|
||||||
@@ -54,6 +82,7 @@ $document = new Document('packt.html', true);
|
|||||||
|
|
||||||
$booksData = [];
|
$booksData = [];
|
||||||
$books = $document->find('.product-line.unseen');
|
$books = $document->find('.product-line.unseen');
|
||||||
|
$books = array_slice($books, 0, 1);
|
||||||
foreach ($books as $book) {
|
foreach ($books as $book) {
|
||||||
|
|
||||||
// print_r($book->html());
|
// print_r($book->html());
|
||||||
@@ -68,6 +97,8 @@ foreach ($books as $book) {
|
|||||||
$bookData['isbn'] = $book->first('div[isbn]::attr(isbn)');
|
$bookData['isbn'] = $book->first('div[isbn]::attr(isbn)');
|
||||||
$bookData['img'] = $book->first('img[class*=imagecache]::attr(src)');
|
$bookData['img'] = $book->first('img[class*=imagecache]::attr(src)');
|
||||||
$bookData['url'] = $book->first('div[class*=product-thumbnail]')->first('a::attr(href)');
|
$bookData['url'] = $book->first('div[class*=product-thumbnail]')->first('a::attr(href)');
|
||||||
|
$bookData['info'] = getBookInfo($bookData['url']);
|
||||||
|
|
||||||
|
|
||||||
$booksData[] = $bookData;
|
$booksData[] = $bookData;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user