77 lines
1.8 KiB
PHP
77 lines
1.8 KiB
PHP
<?php
|
|
include 'vendor/autoload.php';
|
|
|
|
use DiDom\Document;
|
|
|
|
$settings = include 'settings.php';
|
|
|
|
$loginData = [
|
|
'email' => $settings['email'],
|
|
'password' => $settings['password'],
|
|
'op' => 'Login',
|
|
'form_build_id' => 'form-fba4b62ee04aafbf045b1d9ae019d90b',
|
|
'form_id' => 'packt_user_login_form'
|
|
];
|
|
|
|
|
|
function c($url, $post = [])
|
|
{
|
|
$cookie = "cookie.txt";
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS,
|
|
http_build_query($post));
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
|
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
|
|
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
|
|
|
|
// receive server response ...
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
$server_output = curl_exec($ch);
|
|
strlen($server_output);
|
|
|
|
// $info = curl_getinfo($ch);
|
|
|
|
|
|
curl_close($ch);
|
|
|
|
return $server_output;
|
|
|
|
|
|
}
|
|
|
|
|
|
//$return = c('https://www.packtpub.com/', $loginData);
|
|
//$return = c('https://www.packtpub.com/account/my-ebooks');
|
|
//var_dump($return);
|
|
//var_dump($return);
|
|
//$document = new Document($return);
|
|
|
|
$document = new Document('packt.html', true);
|
|
|
|
$booksData = [];
|
|
$books = $document->find('.product-line.unseen');
|
|
foreach ($books as $book) {
|
|
|
|
// print_r($book->html());
|
|
$bookData = [];
|
|
$bookData['title'] = str_replace(["\r\n"], '', trim($book->first('.title::text')));
|
|
$bookData['nid'] = (int)$book->attr('nid');
|
|
|
|
$bookData['pdf'] = $book->first('a[href$=pdf]::attr(href)');
|
|
$bookData['epub'] = $book->first('a[href$=epub]::attr(href)');
|
|
$bookData['mobi'] = $book->first('a[href$=mobi]::attr(href)');
|
|
$bookData['code'] = $book->first('a[href*=code_download]::attr(href)');
|
|
|
|
$booksData[] = $bookData;
|
|
|
|
}
|
|
print_r($booksData);
|
|
|
|
|
|
|
|
//print_r($return);
|