javascript - 雅虎查询语言 - RSS

标签 javascript rss yql

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 提要。不幸的是,它没有正确加载提要,所以我无法做这些事情。此提要使用 Google Feeds Api 正确加载,但由于该提要很快就会被弃用,我尝试转向在 Javascript 中使用不同的 RSS 加载方法(跨域)。我对 YQL url 的操作有误吗?

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

最佳答案

使用以下 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 uses the robots.txt file on your server to determine the Web pages accessible from your site. YQL uses the user-agent "Yahoo Pipes 2.0" when accessing the robots.txt file and checks it for allows/disallows from this user agent. If the robots.txt check does prevent YQL from accessing your content, it will then fetch the target page using a different user agent:

因此,要允许 YQL 访问您的内容,只需将“Yahoo Pipes 2.0”添加到 robots.txt 的相关部分即可。例如:

User-agent: Yahoo Pipes 2.0
Allow: /

引用文献

关于javascript - 雅虎查询语言 - RSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28437932/

相关文章:

javascript - 动态 JavaScript 对象属性值

javascript - 从列表标签和表格标签中删除 HTML 中的空白

parsing - 如何创建一个自动新闻网站?

json - 是否可以让 YQL 在单个请求中从站点返回多个 JSON 结果?

javascript - 我应该使用什么 Meteor 事件处理程序来提交 onchange 表单

javascript - 显示 future 的日期和时间

php - 如何对相似的新闻进行分组

python - 从标准输入读取时如何处理索引

jQuery读取并输出JSON数据

java - Android 用 YQL 数据解析 XML