Skip to content

Instantly share code, notes, and snippets.

@iannono
Created August 15, 2013 08:35
Show Gist options
  • Save iannono/6239257 to your computer and use it in GitHub Desktop.
Save iannono/6239257 to your computer and use it in GitHub Desktop.
fetch_asciicast_with_auth
#!/usr/bin/env ruby
##encoding:utf-8
require 'open-uri'
require 'nokogiri'
require 'stringio'
require 'watir-webdriver'
def generate_cast_url(link)
link + "?view=asciicast"
end
def generate_file_name(cast_url)
cast_url.slice(/\/\d+.*\?/).gsub(/[\/\?]/,'') + '.html'
end
# login github with your name and password
user_name = "name"
password = "password"
# change the browser type with your own
# btw: you should out of the wall if you are in c h i n a
browser = Watir::Browser.new :firefox
browser.goto "http://railscasts.com/login"
browser.text_field(name: 'login').set(user_name)
browser.text_field(name: 'password').set(password)
browser.button(name: 'commit').click
rss_url = 'http://railscasts.com/subscriptions/WbnCA6UR0xak0TrMUSaGQg/episodes.rss'
rss_doc = Nokogiri::XML(open(rss_url))
rss_doc.css('item link').each do |link|
cast_url = generate_cast_url(link.text)
file_name = generate_file_name(cast_url)
browser.goto cast_url
cast_html = Nokogiri::HTML(browser.html)
ascii_content = cast_html.css('.asciicast').inner_html()
File.open(file_name, "w") do |file|
file.puts ascii_content
end
end
browser.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment