Get title from YouTube videos

前端 未结 17 1983
抹茶落季
抹茶落季 2020-12-07 17:30

I want to extract the Title of YouTube\'s videos. How can I do this?

Thanks.

17条回答
  •  醉酒成梦
    2020-12-07 17:56

    Using JavaScript data API:

    var loadInfo = function (videoId) {
        var gdata = document.createElement("script");
        gdata.src = "http://gdata.youtube.com/feeds/api/videos/" + videoId + "?v=2&alt=jsonc&callback=storeInfo";
        var body = document.getElementsByTagName("body")[0];
        body.appendChild(gdata);
    };
    
    var storeInfo = function (info) {
        console.log(info.data.title);
    };
    

    Then you just need to call loadInfo(videoId).

    More informations are available on the API documentation.

提交回复
热议问题