1. Go to this page and download the library: Download vantoozz/proxy-scraper 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/ */
vantoozz / proxy-scraper example snippets
declare(strict_types=1);
use function Vantoozz\ProxyScraper\proxyScraper;
declare(strict_types=1);
use function Vantoozz\ProxyScraper\proxyScraper;
declare(strict_types=1);
use Vantoozz\ProxyScraper\Exceptions\ScraperException;
use function Vantoozz\ProxyScraper\guzzleHttpClient;
use function Vantoozz\ProxyScraper\proxyScraper;
() . "\n";
}
declare(strict_types=1);
use Vantoozz\ProxyScraper\Exceptions\ScraperException;
use Vantoozz\ProxyScraper\HttpClient\HttpClientInterface;
use function Vantoozz\ProxyScraper\proxyScraper;
tring";
}
};
$scraper = proxyScraper($httpClient);
try {
echo $scraper->get()->current()->getIpv4(). "\n";
} catch (ScraperException $e) {
echo $e->getMessage() . "\n";
}
declare(strict_types=1);
use Vantoozz\ProxyScraper\Scrapers;
use function Vantoozz\ProxyScraper\guzzleHttpClient;
;
}
declare(strict_types=1);
use Vantoozz\ProxyScraper\Scrapers;
use function Vantoozz\ProxyScraper\guzzleHttpClient;
Scrapers\FreeProxyListScraper($httpClient));
$compositeScraper->addScraper(new Scrapers\CoolProxyScraper($httpClient));
$compositeScraper->addScraper(new Scrapers\SocksProxyScraper($httpClient));
foreach ($compositeScraper->get() as $proxy) {
echo $proxy . "\n";
}
declare(strict_types=1);
use Vantoozz\ProxyScraper\Exceptions\ScraperException;
use Vantoozz\ProxyScraper\Ipv4;
use Vantoozz\ProxyScraper\Port;
use Vantoozz\ProxyScraper\Proxy;
use Vantoozz\ProxyScraper\Scrapers;
// Fake scraper throwing an exception
$compositeScraper->addScraper(new class implements Scrapers\ScraperInterface {
public function get(): Generator
{
throw new ScraperException('some error');
}
});
// Fake scraper with no exceptions
$compositeScraper->addScraper(new class implements Scrapers\ScraperInterface {
public function get(): Generator
{
yield new Proxy(new Ipv4('192.168.0.1'), new Port(8888));
}
});
//Run composite scraper
foreach ($compositeScraper->get() as $proxy) {
echo $proxy . "\n";
}
declare(strict_types=1);
use Vantoozz\ProxyScraper\Exceptions\ScraperException;
use function Vantoozz\ProxyScraper\proxyScraper;
tMessage() . "\n";
});
declare(strict_types = 1);
use Vantoozz\ProxyScraper\Exceptions\ValidationException;
use Vantoozz\ProxyScraper\Ipv4;
use Vantoozz\ProxyScraper\Port;
use Vantoozz\ProxyScraper\Proxy;
use Vantoozz\ProxyScraper\Scrapers;
use Vantoozz\ProxyScraper\Validators;
new Validators\ValidatorPipeline;
$validator->addStep(new Validators\Ipv4RangeValidator);
foreach ($scraper->get() as $proxy) {
try {
$validator->validate($proxy);
echo '[OK] ' . $proxy . "\n";
} catch (ValidationException $e) {
echo '[Error] ' . $e->getMessage() . ': ' . $proxy . "\n";
}
}
declare(strict_types=1);
use Vantoozz\ProxyScraper\Proxy;
use Vantoozz\ProxyScraper\Scrapers;
use function Vantoozz\ProxyScraper\guzzleHttpClient;
as $metric) {
echo $metric->getName() . ': ' . $metric->getValue() . "\n";
}
$httpClient = new \Vantoozz\ProxyScraper\HttpClient\Psr18HttpClient(
new \Http\Adapter\Guzzle6\Client(new \GuzzleHttp\Client([
'connect_timeout' => 2,
'timeout' => 3,
])),
new \Http\Message\MessageFactory\GuzzleMessageFactory
);