diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5d014d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +settings.php +cookie.txt +vendor/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..404a2ed --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "imangazaliev/didom": "^1.13" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..76346de --- /dev/null +++ b/composer.lock @@ -0,0 +1,64 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "f9f9f5cd3cfa4a3b2acc09d04bf4ec3f", + "packages": [ + { + "name": "imangazaliev/didom", + "version": "1.13", + "source": { + "type": "git", + "url": "https://github.com/Imangazaliev/DiDOM.git", + "reference": "10c4033d56e599f09183959ed90bf17519b9e38b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Imangazaliev/DiDOM/zipball/10c4033d56e599f09183959ed90bf17519b9e38b", + "reference": "10c4033d56e599f09183959ed90bf17519b9e38b", + "shasum": "" + }, + "require": { + "php": ">=5.4" + }, + "require-dev": { + "phpunit/phpunit": "^4.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "DiDom\\": "src/DiDom/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Imangazaliev Muhammad", + "email": "imangazalievm@gmail.com" + } + ], + "description": "Simple and fast HTML parser", + "homepage": "https://github.com/Imangazaliev/DiDOM", + "keywords": [ + "didom", + "html", + "parser", + "xml" + ], + "time": "2017-12-08T15:20:07+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/packt.php b/packt.php new file mode 100644 index 0000000..392deb8 --- /dev/null +++ b/packt.php @@ -0,0 +1,61 @@ + $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); diff --git a/settings.example.php b/settings.example.php new file mode 100644 index 0000000..168eef0 --- /dev/null +++ b/settings.example.php @@ -0,0 +1,4 @@ + 'mail@example.com', + 'password' => 'plain_text_password_here'];