【问题标题】:YQL and cURL - Quote characters are not returned properlyYQL 和 cURL - 引号字符未正确返回
【发布时间】:2010-06-24 00:15:49
【问题描述】:

我正在使用 YQL 进行一些屏幕抓取,并且没有正确返回任何类似引号的字符。

例如,被抓取页面上的标记是:

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;

这是 cURL 问题还是 YQL 问题,我需要做些什么来解决它?

谢谢!

【问题讨论】:

    标签: curl yql


    【解决方案1】:

    这听起来像是字符编码问题。您正在抓取的站点可能正在使用 head 元素中的元标记设置字符集,而不是配置服务器以正确识别 http 标头中的字符编码。找出站点使用的字符编码(您应该能够在浏览器的视图菜单中找到它)并将字符集键添加到您的 YQL 查询中。

    YQL 指南中的示例:

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

    【讨论】:

      【解决方案2】:

      源页面由 IIS 和 ASP 提供。我最终不得不做一个简单的搜索和替换,比如:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-21
        • 1970-01-01
        • 1970-01-01
        • 2013-05-29
        • 2019-05-24
        相关资源
        最近更新 更多