2015-02-10 212 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:/

參考