We want to show how one can make a Curl download file from a server. See comments in the code as explanations.
// open file descriptor
$fp = fopen ("image.png", 'w+') or die('Unable to write a file');
// file to download
$ch = curl_init('http://scraping.pro/ewd64.png');
// enable SSL if needed
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// output to file descriptor
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// set large timeout to allow curl to run for a longer time
curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
curl_setopt($ch, CURLOPT_USERAGENT, 'any');
// Enable debug output
curl_setopt($ch, CURLOPT_VERBOSE, true);
Recently I was challenged to make a script that would authenticate through a bot-proof login from and redirect to a logged in page. more…
We’ve already introduced you to the theory behind the new NO CAPTCHA reCAPTCHA, but now we come to the practical integration part. Here we’ll share how to insert and configure “NO CAPTCHA reCAPTCHA” into a web page. more…
Suppose we want to set only one exception handler function for all exceptions in the scraper program. This exception handler might be working for a multi-level program. Here is how it works in PHP. more…
The DOMXPath class is a convenient and popular means to parse HTML content with XPath. more…
In this post, I’ll explain how to do a simple web page extraction in PHP using cURL, the ‘Client URL library’.
If you want to use regular expressions in your PHP program the best way is to use so called preg-functions (they wrap Perl-Compatible Regular Expressions library so sometimes they are called PCRE functions). Of course, there’re some other function sets like ereg and mb_ereg but they are quite outdated and in this article we’ll focus on preg functions only.