Script yang saya gunakan
function fungsiCurl($url){ $data = curl_init(); curl_setopt($data, CURLOPT_RETURNTRANSFER, 1); curl_setopt($data, CURLOPT_URL, $url); curl_setopt($data, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8')); curl_setopt($data, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); $hasil = curl_exec($data); curl_close($data); return $hasil; } $url = fungsiCurl('http://website.yang.mau.di.grab/'); print_r($url);
Contoh karakter aneh yang muncul di hasil grabbing website dengan PHP
tambahkan discript diatas
curl_setopt($data, CURLOPT_ENCODING, 'gzip,deflate');
sehingga hasil akhirnya menjadi
function fungsiCurl($url){ $data = curl_init(); curl_setopt($data, CURLOPT_RETURNTRANSFER, 1); curl_setopt($data, CURLOPT_URL, $url); curl_setopt($data, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8')); curl_setopt($data, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($data, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); $hasil = curl_exec($data); curl_close($data); return $hasil; } $url = fungsiCurl('http://website.yang.mau.di.grab/'); print_r($url);
coba lagi grab situs yang anda targetkan, di contoh yang saya gunakan hasilnya seperti dibawah ini