Reputation: 2098
I'm making a greasemonkey script to extract video URL code from youtube result: I have this:
// ==UserScript==
// @name extract
// @namespace here
// @include http://stackoverflow.com/
// @grant GM_xmlhttpRequest
// @version 0.1
// ==/UserScript==
window.setTimeout(conseguir_articulos_youtube, 5000);
function conseguir_articulos_youtube(){
GM_xmlhttpRequest({
method: "GET",
url: "http://www.youtube.com/results?search_sort=video_date_uploaded&uni=3&search_type=videos&search_query=humor",
onload: on_load_extract
});
}
function on_load_extract(data){
var datos=data.responseText;
alert(datos);
}
I use xmlHttpRequest to retrieve the content of youtube, but the code of the page present in the response is not complete. There is a form to retrieve the complete source code of a page in javascript?
Upvotes: 0
Views: 206
Reputation: 169
It seems you are receiving the whole source code of the page. The problem is that the page is using AJAX calls of its own to further load other resources, thus leaving you with an "incomplete" version of the page.
I recommend using the YouTube API for YouTube integration instead of scraping the HTML.
I've never used it myself, so I cannot give you a quick reference of it, but I'm sure it's quite simple to use. :) Hope it helps!
Upvotes: 2