1. Go to this page and download the library: Download pandcar/atomic library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// В конструкторе
$atom = new Atomic([
'path_tmp' => __DIR__ .'/tmp'
]);
// Одиночная настройка
$atom->set('path_tmp', __DIR__ .'/tmp');
// Множественная
$atom->set([
// Папка для временных файлов (cookie, phantomjs-tmp)
'path_tmp' => __DIR__ .'/tmp',
// Имя куки
'name_cookie' => 'atomic',
// Кука по умолчанию
'path_cookie' => __DIR__ .'/tmp/atomic.cookie',
// Ограничение времени на подключение (сек.)
'connect_timeout' => 20,
// Ограничение времени на выполнение запроса (сек.)
'timeout' => 60,
// Прокси сервер по умолчанию
'proxy' => 'http://login:password@host:port',
// Лямбда до выполнения $this->request(); влияющая на запрос
'callback_request_start' => function($query){},
// Лямбда после каждого выполнения $this->request();
'callback_request_end' => function($query, $response){},
// Путь до PhantomJS
'phantomjs_path' => __DIR__ .'/bin/phantomjs.exe',
// Ключь сервиса ruCaptcha
'rucaptcha_key' => '6df61bfae47c6a9214729143c4fc9a82',
// HTTP заголовки/планы по умолчанию
'headers' => [
'default' => [
'Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
'Upgrade-Insecure-Requests: 1',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36',
],
'ajax' => [
'Accept: */*',
'Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36',
'X-Requested-With: XMLHttpRequest',
],
],
]);
// Простой get запрос
$result = $atom->request('http://site.ru/');
// Мульти запрос
$array = $atom->request_multi([
[
'url' => 'http://site.ru/?foo=bar'
],
[
'url' => 'http://sitetwo.ru/'
],
]);
// Все опции
$result = $atom->request([
// url запроса
'url' => 'http://site.ru/',
// Конструктор query
'get' => [
'foo' => 'bar',
],
// Ограничение времени на подключение (сек.)
'connect_timeout' => 5,
// Ограничение времени на выполнение запроса (сек.)
'timeout' => 20,
// Простой Post (приоритет)
'post' => 'foo=bar&ddd=ccc',
// Конструктор Post
'post/build' => [
'username' => $login,
'password' => $password,
'submit' => 'Войти',
],
// Загрузка контента в файл
'file_handle' => $fopen,
// План заголовков
'headers_plan' => 'ajax',
// Заголовки (приоритет)
'headers' => [
'Referer: http://site.ru/',
],
// Сливает заголовки с заголовками по умолчанию
'headers/merge' => [
'Referer: http://site.ru/',
],
// Прокси
'proxy' => 'http://login:password@host:port',
// Куки (приоритет)
'cookie' => 'foo=bar&ddd=ccc',
// Конструктор cookie
'cookie/build' => [
'foo' => 'bar',
],
// Путь к файл cookie
'cookie_path' => __DIR__ .'/tmp/atomic.cookie',
// Лямбда функции cURL (header, progress, read, write)
'callbacks' => [
'write' => function($curl, $content){
return strlen($content);
}
],
// Прямая установка параметров cURL (приоритет)
'curl_setopt' => [
CURLOPT_HEADER => true,
],
// Исключения Заголовков ответа из результата cURL
'no_headers' => true,
// Исключения Тела ответа из результата cURL
'no_body' => true,
// Сменить кодировку контента из windows-1251 на utf8
'charset' => 'windows-1251',
// Следовать по заголовкам Location
'follow_location' => true,
// Форма данных (headers, body, array, json, xml)
'form' => 'json',
// Включает отладку
'debug' => true,
// Не вызывать callback_request_*
'no_callback' => true,
]);
// Получить массив кук
$array = $atom->getCookie();
// Установка куки
$atom->setCookie($domen, $key, $value, $time);
// Удаление одной или всех кук (если без параметров)
$atom->removeCookie($key, $domen);
$string = $atom->regexp('>([^<]+)</span>', $html);
// Получает второй элемент
$string = $atom->regexp('>([^<]+)</span>, <b>([0-9]+?)', $html, 2);
$array = $atom->regexp('>([^<]+)</span>, <b>([0-9]+?)', $html, true);