CURL extracts encoded HTML from Pirate Bay

I am creating a script that cleans the site www.piratebay.se . The script worked fine two to three days ago, but now I have problems with it.

This is my code:

$URL = 'http://thepiratebay.se';
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($ch, CURLOPT_COOKIE, "language=pt_BR; c[thepiratebay.se][/][language]=pt_BR");

$fonte = curl_exec ($ch);

curl_close ($ch);
echo $fonte;

The answer of this code is not pure HTML, but it looks like this:

[S8N> k9- ى km7 $ 8.v͕ $ hyGSg: ӷ> 5 ʱ aor&.v)) dw 8w lcu "" 1 F * G 2 $ 6 C} z (bw 4Ƒz6 S t4 K x 6u ~ T ACJb T ^ 3 USPI : Mf n '4 XE QQ & c5' 'β TY] DQ nBfS} a% R) Zn ̙ 8IB aL

I have already tried using the user agent in .htaccess, PHP and cURL, but have not succeeded.

+4
source share
1 answer

Add this:

curl_setopt($ch, CURLOPT_ENCODING , "gzip");

Tested in my local environment, works great with it.

+10

Source: https://habr.com/ru/post/1539587/


All Articles