Skip to content

Instantly share code, notes, and snippets.

@breim
Created February 22, 2015 22:58
Show Gist options
  • Select an option

  • Save breim/198a113cf8b40fac88e7 to your computer and use it in GitHub Desktop.

Select an option

Save breim/198a113cf8b40fac88e7 to your computer and use it in GitHub Desktop.
Countries Crawler
task :countries => :environment do
agent = Mechanize.new { |agent| agent.user_agent_alias = 'Linux Mozilla' }
page = agent.get('http://www.flightradar24.com/data/airports/')
countries = page.search('#countriesList a').map { |link| [link.attributes['title'].value ,link['href'] ] }
countries.each do |country|
@country = Country.new(name: country[0], url: country[1])
@country.save!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment