-
-
Save caridy/1327725 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var YUI = require("yui3").YUI; | |
YUI({ | |
debug: true | |
}).use('node', 'io', function(Y) { | |
//Messing with the main page.. | |
Y.one('title').set('innerHTML', 'Digg News Headlines'); | |
//Creating the list that we will append the remote data to | |
var ul = Y.one('body').appendChild(Y.Node.create('<ul></ul>')); | |
//Creating a sandboxed instance that we will bind to the remote page that we fetch | |
YUI().use('node', function(remotePage) { | |
//The page we are fetching | |
var url = 'http://digg.com/news'; | |
//This will call io under the hood and get the content of the URL, | |
//It will then dump the content of that page into this sandboxed document. | |
remotePage.fetch(url, function() { | |
//Get all the news items from the remote page. | |
var newsItems = remotePage.all('#story-items h3'); | |
//Iterate them | |
newsItems.each(function(n) { | |
//Import this "A" node into the outside instances document | |
var a = ul.importNode(n.one('a'), true); | |
//Clean up the relative URL's of hrefs | |
a.set('href', 'http://digg.com' + a.get('href')); | |
//Append the new node to the list | |
ul.appendChild(Y.Node.create('<li></li>')).append(a); | |
}); | |
//Now, we can print the "outer" instances html and drop it to the screen | |
console.log(Y.one('doc').get('outerHTML')); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Digg News Headlines</title> | |
</head> | |
<body> | |
<ul> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/is_college_a_bad_investment">Is college a bad investment?</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/29_meals_where_the_presentation_is_more_important_than_the_actual_food_itself_photofind_com_can_t_read_have_fun_anyway">29 Meals Where The Presentation Is More Important Than The Actual Food Itself | PhotoFind.com - c...</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/famous_logos_with_hidden_images">Famous Logos with Hidden Images</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/nokia_replaces_ceo_with_microsoft_exec_to_save_itself">Nokia replaces CEO with Microsoft exec to save itself</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/14_incredible_wood_sculptures">14 Incredible Wood Sculptures</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/a_look_at_apple_s_updated_iphone_configuration_utility">A look at Apple's updated iPhone Configuration Utility</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/they_won_t_even_know_what_hit_em_pic">They Won't Even Know What Hit 'Em [Pic]</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/blow_job_supplier_nailed_by_uk_electronics_law">Blow Job Supplier Nailed by UK Electronics Law</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/6_movies_that_didn_t_realize_they_let_the_villain_win">6 Movies That Didn't Realize They Let The Villain Win</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/qvaq_a_key_to_easy_social_communication_online">Qvaq: A Key to Easy Social Communication Online</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/5_fictional_stories_you_were_taught_in_history_class">5 Fictional Stories You Were Taught in History Class</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/blooper_reels_from_the_original_star_trek_series">Blooper Reels From The Original Star Trek Series</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/top_ten_disney_properties_underrepresented_in_kingdom_hearts">Top Ten Disney Properties Underrepresented in Kingdom Hearts</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/9_awesome_slacker_jobs_you_could_actually_have">9 Awesome Slacker Jobs You Could Actually Have</a> | |
</li> | |
<li> | |
<a class="story-title" target="_blank" href="http://digg.com/story/r/microsoft_xbox_live_team_says_too_gay_to_play">Microsoft Xbox Live Team Says Too Gay To Play</a> | |
</li> | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment