Crawl and parse pages through LundProxy with PHP cURL.
Crawl and parse pages through LundProxy with PHP cURL. This example uses Rotating Proxies as the default gateway and can be adapted by replacing endpoint and routing credentials.
Install the client and create a file.
Use a clean project environment and pin tested dependency versions for production. The example target is a public scraping sandbox.
Enable the curl and dom extensionsLoad proxy secrets from the environment.
The proxy username is not the LundProxy website login. Copy the complete username and password generated for the selected proxy product.
PROXY_USER=user-pool-crawlerPROXY_PASS=your-secretscrape.php
Copy the code into the named file, set credentials, and run it from the project environment.
<?php
$curl = curl_init("https://quotes.toscrape.com/");
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_PROXY => "proxy.lundproxy.com",
CURLOPT_PROXYPORT => 36923,
CURLOPT_PROXYUSERPWD =>
getenv("PROXY_USER") . ":" . getenv("PROXY_PASS"),
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_FAILONERROR => true,
]);
$html = curl_exec($curl);
if ($html === false) {
throw new RuntimeException(curl_error($curl));
}
curl_close($curl);
$document = new DOMDocument();
@$document->loadHTML($html);
$xpath = new DOMXPath($document);
echo $xpath->query('//*[contains(@class, "quote")]')->length . PHP_EOL;
Keep the important behavior visible.
Add workload-specific controls before scale.
Test representative targets, response sizes, routing policy, concurrency, retries, validation, and completion window. Collect only public data you are authorized to access.
cURL + DOMXPath questions.
Why not put credentials in the proxy URL?
CURLOPT_PROXYUSERPWD avoids URL parsing problems with special characters.
How do I use SOCKS5?
Set CURLOPT_PROXYTYPE to CURLPROXY_SOCKS5_HOSTNAME and use assigned SOCKS access details.
What extensions are required?
Enable cURL for requests and DOM for DOMDocument and DOMXPath.