2015-10-12 109 views
0

我正在解析互联网报纸的columinst页面。我有问题,这个网站使用php解析html simple_html_dom

http://www.sozcu.com.tr/kategori/yazarlar/

解析是在起始工作正常,但它停止工作。

这里是我的代码

$curl_handle=curl_init(); 
curl_setopt($curl_handle, CURLOPT_URL,$gazeteAdress); 
//curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); 
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'mozilla'); 
$query = curl_exec($curl_handle); 
curl_close($curl_handle); 
$html = new simple_html_dom(); 
$html->load($query); 

我不知道为什么我的代码,有时并不解析网站,所以我在想connection_timeout。但这不是问题,所以我想用curl来打印html页面。

echo $html; 

这是结果。 (有时我的代码不能正确解析html页面) enter image description here

为什么html标记不会到来,为什么会看到像这样的结果。谁能帮忙?

回答

1

内容返回压缩的顶部,这样你应该指定接受编码“的gzip,紧缩”报头卷曲。

请添加此行
curl_setopt($curl_handle, CURLOPT_ENCODING, "gzip,deflate");
此后
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'mozilla');

0

添加这对你的PHP脚本

header('Content-Type: text/html; charset=utf-8'); 
+0

已经这样: Beyaz

+0

你不需要这个,只有<?php header('Content-Type:text/html; charset = utf-8'); – user1919915

+0

配偶有时是工作,但有时候不是。这不是土耳其人物问题 – Beyaz