Reputation: 13545
I would like to get part of the youtube page source code.
I tried cross domain ajax technique such as yahoo yql , JsonP. With the help of the yahoo YQL , I can grab part of the source code. However, since it may be the different domain, what I get from the ajax response text do not have the parameter in it. How to fix the problem without using server side program ? Thanks
Link: http://www.youtube.com/watch?v=F6JiCJ5x3Qw
You can see from element inspector , there is an line <div id="player-api" class="player-width player-height off-screen-target watch-content player-api" style="overflow: hidden;">
And I would like to get all the element within this div
Upvotes: 0
Views: 1897
Reputation: 4016
Use a proxy script at your own server, if you have no control over the endpoint (youtube in this case)
So instead of calling a youtube url you will call yourproxyscript?some_arguments. Now the "yourproxyscript" will load youtube url and return it to your ajax call, bypassing any cross-domain issues.
Upvotes: 1
Reputation: 3332
In this case, the simplest thing to do may be to use the YouTube API.
However, in general, what you'd want to do is load the page into an iFrame rather than a div:
<iframe id="iframe" src="http://targetwebsite.com/"></iframe>
And then get the HTML of the iFrame as follows:
document.getElementById('iframe').contentWindow.document.body.innerHTML
Upvotes: 2