我正在尝试使用以下代码下载网页:
function request($url){
$curl_timeout = 5;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $curl_timeout);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
echo request('http://www.tsetmc.com/Loader.aspx?ParTree=15');
此代码打印的内容如下:
�"X��}koǵ�� ����n2��٬����'�º���1$[��#��H���������RQ,+���k��
我做错了什么?
答案 0 :(得分:1)
只需将此添加到curl实例即可。
curl_setopt($curl, CURLOPT_ENCODING , "gzip");
你应该没事,在这里阅读更多(http://php.net/manual/en/function.curl-setopt.php)