2015-02-10 87 views
1
var site = 'www.mysite.com/news.aspx?rss=1'; 
var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + site + '"') + '&format=xml'; 
$.get(yql).done(function (rss) 
{ 
     //do the Things 
} 

目前我有这个功能试图加载外部网站的RSS提要。不幸的是,它没有正确加载Feed,所以我不能做这些事情。此Feed使用Google Feeds Api正确加载,但由于这种情况很快就被驳斥了,我正试图转移到使用Javascript加载RSS的其他方法(跨域)。有没有我不正确的YQL网址?雅虎查询语言 - RSS

 error="Redirected to a robots.txt restricted URL: http(s)://www.mySite.com/news.aspx?rss=1" 

回答

0

使用以下URL映射作为测试:

'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="http://www.bls.gov/feed/empsit.rss"') 

其产生有效YQL查询:

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fwww.bls.gov%2Ffeed%2Fempsit.rss%22 

具有以下JSON交替输出:

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fwww.bls.gov%2Ffeed%2Fempsit.rss%22&format=json 

并保持以下限制请记住排除故障:

YQL使用服务器上的robots.txt文件来确定可从您的站点访问的网页。 YQL在访问robots.txt文件时使用用户代理“Yahoo Pipes 2.0”,并检查它是否允许来自此用户代理。如果robots.txt的检查确实防止YQL访问您的内容,它就会使用不同的用户代理获取目标页面:

因此,为了让您的内容YQL访问,只需添加“雅虎管道2.0”到robots.txt的相关部分。例如:

User-agent: Yahoo Pipes 2.0 
Allow:/

参考