How to scrape the data from website using CURL?

To scrap the data from website, Website must be public and open for scrapable. When scraping data from the website, i can be in different formats like json, html, xml etc. Most of the websites don’t allow direct scraping, they required user authentication.
In the blow code, Just update the $url variable to which websites data you want to scrap.

<?php
$ch = curl_init();
$url = "http://www.thetechdiary.com/";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>

Leave a Comment