Skip to content

Instantly share code, notes, and snippets.

@D3MZ
Created November 14, 2012 22:37
Show Gist options
  • Save D3MZ/4075355 to your computer and use it in GitHub Desktop.
Save D3MZ/4075355 to your computer and use it in GitHub Desktop.
grab links for railcasts episodes
require 'mechanize'
@agent = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' }
url = "http://railscasts.com/episodes/13-dangers-of-model-in-session"
page = @agent.get url
links = []
while page.link_with(:text => /next/i)
break if page.search("//*[@id=\"episode\"]/div[1]/ul/li[2]/a").first.nil?
links << page.search("//*[@id=\"episode\"]/div[1]/ul/li[2]/a").first.attributes["href"].value
page = page.link_with(:text => /next/i).click
end
axel = links.collect { |link| "axel -a #{link}" }.join("\n")
File.open(ENV['HOME']+"/railscasts_axel.txt", 'w') {|f| f.write(axel) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment