gpt4 book ai didi

php - cURL 正在从 Pirate Bay 检索编码的 HTML

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:02:47 24 4
gpt4 key购买 nike

我正在创建一个脚本来抓取网站 www.piratebay.se。脚本在两三天前工作正常,但现在我遇到了问题。

这是我的代码:

$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;

此代码的响应不是干净的 HTML,而是如下所示:

��[s8N>��k��9��-ىmI7��$��8��.v��͕����$h����y��G��Sg:ӷ>��5������ʱ��aor&����.v)����������) d��w��8w��l����c��u""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��`'β��T Y]D��Q��nBfS��}a��%�� ����R) ��Zn��̙ ��8IB��a����L��

我已经尝试在 .htaccess、PHP 和 cURL 上使用用户代理,但没有成功。

最佳答案

添加这个:

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

在我的本地环境中测试过,工作正常。

关于php - cURL 正在从 Pirate Bay 检索编码的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23520466/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com