Getting 403 error scrapping sites behind CloudFlare, here is a simple Curl method that works
You need
Free RapidApi.com Subscription and A Free Scrapeninja API access
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://scrapeninja.p.rapidapi.com/scrape",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\r
\"url\": \"https://news.ycombinator.com/\"\r
}",
CURLOPT_HTTPHEADER => [
"X-RapidAPI-Host: scrapeninja.p.rapidapi.com",
// GET YOUR KEY HERE https://rapidapi.com/restyler/api/scrapeninja/ AND REPLACE NEXT LINE
"X-RapidAPI-Key: REPLACE-WITH-YOUR-OWN-KEY",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}