Created
February 22, 2015 22:58
-
-
Save breim/198a113cf8b40fac88e7 to your computer and use it in GitHub Desktop.
Countries Crawler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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