Scrape Bill text files

scrape_bill_text.rb
require 'open-uri'
require 'nokogiri'
require 'mechanize'

def get_bill_nums
  doc = Nokogiri::HTML(open("http://leg.colorado.gov/bill-search"))
  bill_nums = doc.css("div.field-name-field-bill-number div.field-items").text.split("\s")
  bill_nums
end

bill_nums = get_bill_nums()
puts bill_nums
bill_nums.each do |bill_num|
  agent = Mechanize.new
  doc = Nokogiri::HTML(open("http://leg.colorado.gov/bills/#{bill_num}"))
  bill_file_url = doc.css("div.recent-bill-text a")[0].attributes["href"].text
  if !File.exists? "files/bills/#{bill_num}.pdf"
    agent.get(bill_file_url).save "files/bills/#{bill_num}.pdf"
  end
end