Skip to content

Instantly share code, notes, and snippets.

@ddd1600
Created December 14, 2014 20:31
Show Gist options
  • Save ddd1600/b5d29be2f895f499cdd2 to your computer and use it in GitHub Desktop.
Save ddd1600/b5d29be2f895f499cdd2 to your computer and use it in GitHub Desktop.
class ScrapeFfiec
attr_reader :b
def initialize
@year = Time.now.year
@b = Watir::Browser.new
@county_fips = []
end
def go(state_fips=13)
urlfx = lambda {|state_fips, county_fips, page_type, page| "http://www.ffiec.gov/census/report.aspx?year=#{@year}&county=#{county_fips}&state=#{state_fips}&report=#{page_type}&page=#{page}" }
@county_fips.each do |cfips|
["demographic", "income", "population", "housing"].each do |page_type|
[1, 2].each do |page_number|
url = urlfx[state_fips, cfips, page_type, page_number]
puts "about to open #{url}"
@b.goto url
next if @b.text =~ /Invalid Search Parameters/
@b.trs[14..-2].each do |tr|
ctfips = tr.tds[0].text
puts "fips is #{ctfips}"
f = FfiecCtData.find_by_fips(ctfips) || FfiecCtData.new
end# of trs w/ data
end# of page_numbers
end# of page_types
end# of county_fips
end# of method
end# of class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment