initial commit

This commit is contained in:
Krzysztof Płaczek
2018-04-06 08:29:05 +02:00
commit 8413a9af38
6 changed files with 137 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
settings.php
cookie.txt
vendor/

0
README.md Normal file
View File

5
composer.json Normal file
View File

@@ -0,0 +1,5 @@
{
"require": {
"imangazaliev/didom": "^1.13"
}
}

64
composer.lock generated Normal file
View File

@@ -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": []
}

61
packt.php Normal file
View 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);

4
settings.example.php Normal file
View File

@@ -0,0 +1,4 @@
<?php
return ['email' => 'mail@example.com',
'password' => 'plain_text_password_here'];