2010-06-24 22 views
2

我正在使用YQL進行某些屏幕抓取,並且沒有正確返回任何類似引號的字符。YQL和cURL - 引用字符沒有正確返回

例如,頁面被刮上的標記是:

There should not be a 「split between what we think and what we do,」 

這是通過YQL返回:

There should not be a �split between what we think and what we do,� 

這也有蜱和反單引號發生。

我的JS是這樣的:

var qurlString = '&url=' + encodeURIComponent(url); 
$.ajax({ 
    type: "POST", 
    url: "/k_sys/qurl.php", 
    datatype: "xml", 
    data: qurlString, 
    success: function(data) { 
    //do something 
    } 
}); 

而且我qurl.php是這樣的:

$BASE_URL = "http://query.yahooapis.com/v1/public/yql"; 
    $url = my scraped site url; 
    $yql_query = "select * from html where url='$url'"; 
    $yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=xml"; 
    $session = curl_init($yql_query_url); 
    curl_setopt($session, CURLOPT_RETURNTRANSFER,true); 
    $xml = curl_exec($session); 
    echo $xml; 

這是捲曲的問題或YQL問題,以及我需要做些什麼來解決什麼它?

謝謝!

回答

0

頁面由IIS和ASP所服務的源。我結束了不得不做一個簡單的搜索和替換,如:

str_ireplace(chr(145), chr(39), $html) 
1

這聽起來像是一個字符編碼問題。您正在抓取的網站可能會使用頭元素中的元標記設置字符集,而不是配置服務器以正確標識http標頭中的字符編碼。找出網站使用的字符編碼(您應該能夠在瀏覽器的視圖菜單中找到它)並將字符集鍵添加到您的YQL查詢中。從YQL導向

實施例:

select * from html where url='http://example.com' and charset='iso-8559-1'