PHP code example of gregpriday / laravel-zyte-api

1. Go to this page and download the library: Download gregpriday/laravel-zyte-api 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/ */

    

gregpriday / laravel-zyte-api example snippets


use GregPriday\ZyteApi\Facades\ZyteApi;

$url = 'https://example.com';
$response = ZyteApi::extract($url, ['browserHtml' => true]);

// Access the browser-rendered HTML
echo $response['browserHtml'];

$urls = [
    'https://example.com/article1',
    'https://example.com/article2',
    'https://example.com/article3',
];

$responses = ZyteApi::extract($urls, ['article' => true]);

// Access the extracted article data for each URL
foreach ($responses as $url => $articleData) {
    echo "URL: $url\n";
    echo "Headline: {$articleData['headline']}\n";
    echo "Article Body: {$articleData['articleBody']}\n";
    // ...
}

use GregPriday\ZyteApi\Proxy\ZyteClient;

$client = app(ZyteClient::class);
$response = $client->get('https://example.com');

$httpResponseBody = $response->getBody()->getContents();
// ...

use GregPriday\ZyteApi\Facades\ZyteApi;
use GregPriday\ZyteApi\Processors;

$urls = [
    'https://example.com/article1',
    'https://example.com/article2',
    'https://example.com/article3',
];

$responses = ZyteApi::extract($urls, ['article' => true], function ($response) {
    $articleData = $response['article'];

    // Convert article HTML content to Markdown
    $articleData['articleBodyMarkdown'] = Processors::htmlToCleanMarkdown($articleData['articleBodyHtml']);

    return $articleData;
});

// Access the extracted article data and converted Markdown content for each URL
foreach ($responses as $url => $articleData) {
    echo "URL: $url\n";
    echo "Headline: {$articleData['headline']}\n";
    echo "Article Body (HTML): {$articleData['articleBodyHtml']}\n";
    echo "Article Body (Markdown): {$articleData['articleBodyMarkdown']}\n";
    // ...
}
bash
php artisan vendor:publish --provider="GregPriday\ZyteApi\ZyteApiServiceProvider"

ZYTE_API_KEY=your-zyte-api-key-here
ZYTE_API_CONCURRENCY=5
ZYTE_PROXY=your-proxy-url-here