initial commit
This commit is contained in:
61
packt.php
Normal file
61
packt.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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);
|
||||
$document = new Document($return);
|
||||
|
||||
$booksData = [];
|
||||
$books = $document->find('.product-line.unseen');
|
||||
foreach ($books as $book) {
|
||||
$booksData[] = trim($book->first('.title::text'));
|
||||
}
|
||||
print_r($booksData);
|
||||
|
||||
|
||||
|
||||
//print_r($return);
|
||||
Reference in New Issue
Block a user