2015-10-12 108 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