Search code examples
phpjavascripthtmlimagesrc

Scrape/Get IMG Src from separate [EXTERNAL] page (with Javascript?)


I am looking to make a script, where, given a Youtube user it will pull the banner off of their channel. The Youtube channel will be user-inputed.

Example input: thenewboston

Note that, the location of the channel would be http://www.youtube.com/user/thenewboston

And that is how all youtube channels URL's are formatted. Also notice that the banner image is in a div with id="user_banner".

So the ideal output in this case (thenewboston's channel) would be http://i3.ytimg.com/u/JbPGzawDH1njbqV-D5HqKw/profile_header.jpg?v=4bba630b


Solution

  • With Javascript, its difficult as you cannot make cross-site ajax requests. You will probably need to involve php in this. You can do in jQuery,

    $.get(getYTBanner.php, variables)
    

    and in getYTBanner.php, you will need to open this url using file_get_contents or cURL and from there get the banner through html.

    Warning: not actual syntax.