PHP code example of msankhala / parsehub-php

1. Go to this page and download the library: Download msankhala/parsehub-php 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/ */

    

msankhala / parsehub-php example snippets


composer 



use Parsehub\Parsehub;

$api_key = <your-api-key>;
$parsehub = new Parsehub($api_key);
$projectList = $parsehub->getProjectList();
echo $projectList;

$api_key = <your-api-key>;
$api_url = 'https://www.parsehub.com/api/v2';
$log_path = 'path/to/parsehub.log';
$parsehub = new Parsehub($api_key, $api_url, $log_path);
$projectList = $parsehub->getProjectList();
echo $projectList;

// Get project_token and run_token from DB.
$project_token = <get project token from db>
$run_token = <get project token from db>

$parsehub = new Parsehub($api_key);
$project = $parsehub->getProject($project_token);
echo $project;

$parsehub = new Parsehub($api_key);
$data =  $parsehub->getLastReadyRunData($project_token);
print $data;

$parsehub = new Parsehub($api_key);
$data = $parsehub->getRunData($run_token);
print $data;

$parsehub = new Parsehub($api_key);
$run = $parsehub->getRun($run_token);
print $run;

$parsehub = new Parsehub($api_key);
$options = array(
    // Skip start_url option if don't want to override starting url configured
    // on parsehub.
    'start_url' => '<starting url at which crawling starts>'
    // Enter comma separated list of keywords to pass into `start_value_override`
    'keywords' => 'iphone case, iphone copy'
    // Set send_email options. Skip to remain this value default.
    'send_email' => 1,
);
$run_obj = $parsehub->runProject($project_token, $options);
echo $run_obj;

$parsehub = new Parsehub($api_key);
$cancel = $parsehub->cancelProjectRun($run_token);
print $cancel;

$parsehub = new Parsehub($api_key);
$cancel = $parsehub->deleteProjectRun($run_token);
print $cancel;