ahmard/queliwrap

QueryList PHP web scrapper wrapper.

4.0.4 2022-12-21 15:30 UTC

README

Queliwrap is a wrapper that provides easy helper functions around PHP popular web scrapper, QueryList and Guzwrap.

Notice: Queliwrap\Wrapper\Queliwrap::exec() method has been replaced with execute(). exec() now returns psr-7 compliant object while execute() returns QueryList object.

Installation

Make sure you have Composer installed.

composer require ahmard/queliwrap

After installation is done, require Composer's autoloader in your code:

require 'vendor/autoload.php';

Usage

Queliwrap relies on Guzwrap, you might want to dig a little deeper in to it.

use Queliwrap\Client;

Client::get('https://google.com')->execute()
    ->find('ul')->eq(0)
    ->find('li');

Handle errors

use Queliwrap\Client;

try {
    $text = Client::get('https://google.com')->execute()
        ->find('ul')->eq(0)
        ->find('li')
        ->text();
        
    echo $text;
}catch (Throwable $exception){
    echo $exception->getMessage();
}

Submit Form

use Guzwrap\Wrapper\Form;
use Queliwrap\Client;

Client::post(function(Form $form){
    $form->action('http://localhost:8080/rand/guzwrap.php');
    $form->field('name', 'Jane Doe');
    $form->file('image', 'C:\1.jpg');
});

Cookies

Thanks to Guzwrap cookies can be preserved across multiple requests

use Guzwrap\Wrapper\Form;
use Queliwrap\Client;

//Login
Client::create()
    ->referer('http://localhost:8000')
    ->withSharedCookie()
    ->form(function (Form $form){
        $form->action('http://localhost:8000/login');
        $form->method('POST');
        $form->input('email', 'queliwrap@example.com');
        $form->input('password', 1234);
        $form->input('remember_me', 1);
    })->exec();

//View user profile
$queryList = Client::create()
    ->get('http://localhost:8000/users/view')
    ->query(['id' => 2])
    ->withSharedCookie()
    ->execute();

//Find user info
$firstName = $queryList->find('.profile')
    ->find('list-group-item')
    ->eq(0)
    ->text();

echo "First name: {$firstName}";

Documentations

Licence

Queliwrap is MIT licenced.