YQL查询服务现在被雅虎关闭了

Pur*_*One 15 rss json yql

所以现在雅虎关闭了,query.yahooapis.com如下面的消息所示,有没有人知道免费更换?

"重要的EOL通知:截至2019年1月3日星期四,query.yahooapis.com上的YQL服务将被淘汰.这将影响datatables.org的用户以及使用此YQL服务创建功能的开发人员.继续使用我们的免费雅虎天气API,使用 https://weather-ydn-yql.media.yahoo.com/forecastrss作为您的新API端点.请联系yahoo-weather-ydn-api@oath.com获取此免费的机上凭据Yahoo Weather API服务.使用query.yahooapis.com的其他基于YQL的服务将不再运行."

需要替换"//query.yahooapis.com/v1/public/yql?q="我的rss scraper才能工作.

function yql(a, b) {
        return (
          "**//query.yahooapis.com/v1/public/yql?q=**" +
          encodeURIComponent(
            "select * from " +
              b +
              ' where url="' +
              a +
              '" limit ' +
              params.feedcount
          ) +
          "&format=json"
        );
      }
Run Code Online (Sandbox Code Playgroud)

小智 5

我发现了这个,它对我很有用。 https://api.rss2json.com 有一个免费层,它比用于 RSS 到 JSONP 转换的 YQL 更直接。


小智 -3

这是您可能的解决方案。

a) 您需要某种代理来允许使用 ajax 从不同来源加载内容。建议将其列入白名单并添加 CORS 标头等,以防止您的代理被利用。例如,使用以下功能在您的一台服务器上创建一个 php 文件:

$valid_url_regex = '/.*(rss|feed|atom).*/';
$url = $_GET['url'];
if ( !preg_match( $valid_url_regex, $url ) ) exit;

$feeds = file_get_contents($url);
//this is some workaround to get special namespaces into the json
$feeds = str_replace("<content:encoded>","<contentEncoded>",$feeds);
$feeds = str_replace("</content:encoded>","</contentEncoded>",$feeds);
$feeds = str_replace("<media:content ","<mediaContent ",$feeds);
$feeds = str_replace("</media:content>","</mediaContent>",$feeds);

$simpleXml = simplexml_load_string($feeds, "SimpleXMLElement", LIBXML_NOCDATA);//this is for CDATA
$json = json_encode($simpleXml);
header("Access-Control-Allow-Origin: http://yourdomainnamehere");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); 
print $json;
Run Code Online (Sandbox Code Playgroud)

b) 对代理脚本执行异步 ajax 调用并处理数据:

function loadRss(url)
{
    $.ajax({
        url: 'yourserverurl/rssproxy.php?url='+url,
        type: 'GET',          
        success: function(response) {
            handleResponse(JSON.parse(response));
        }
    });
}


function handleResponse(response) { 
    var entries; 

    if(response.entry) //ATOM
        entries = response.entry;
    else if(response.channel.item) //RSS 1/2
        entries = response.channel.item;

    var feedTitle="";

    if(response.title)
        feedTitle = response.title;
    else if(response.channel.title)
        feedTitle = response.channel.title;

    //iterate all news entries
    $.each(entries, function (i, e) {
            console.log("Entry #"+i);
            console.log(e);
            //access the data as necessary like e.content, e.summary, e.contentEncoded etc....
    }
    );

}
Run Code Online (Sandbox Code Playgroud)

几年前我将我的 google rss api 更改为 YQL,现在我今天必须再次执行此操作,花了几个小时,但是这次您不会依赖于某些第 3 方供应商,希望您可以使用新的阅读器代码,直到由于人类对著名的过滤气泡的偏好,RSS 消失了;)

上面的代码只是一个提示,当然,如果您想将响应映射到通用的 YQL 结构,您将需要投入一些时间。我没有那样做,而是根据需要访问了响应的属性。