0

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?

2

1 Answer 1

2

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.