2016-11-27 51 views
0

我試圖使用Chrome和CORS擴展名從YouTube網頁獲取視頻標題。gettint youtube video的標題

$.get('https://www.youtube.com/user/SERLYMAR/videos', function (html) { 
var $html = $(html); 
console.log($html.find('a.yt-ui-ellipsis-2').text()); 

它的工作原理,但列出的標題後,我得到了以下錯誤(多次):

Uncaught ReferenceError: __ytRIL is not defined 
    at HTMLImageElement.onload (http://localhost/extract-titles/:1:2)onload @ (index):1 
(index):1 Uncaught ReferenceError: __ytRIL is not defined(…)onload @ (index):1 
+0

查看評論[這裏](http://stackoverflow.com/questions/39137734/trying-to-configure-youtube-subscribe-button-callbacks) – FrankerZ

+0

@FrankerZ,難道就沒有方案? – bonaca

回答

0

嘗試將dataType爲文本,以防止你的腳本在解析腳本標記你遠程頁面。

$.ajax({ 
    dataType: 'text', 
    url: 'https://www.youtube.com/user/SERLYMAR/videos', 
    success: function (html) { 
     var $html = $(html); 
     console.log($html.find('a.yt-ui-ellipsis-2').text()); 
    } 
});