Last active
August 29, 2015 13:57
-
-
Save crm114/9731721 to your computer and use it in GitHub Desktop.
SpaceApps Challenges ruby scraper
This file contains 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
# gem install nokogiri | |
require 'nokogiri' | |
require 'open-uri' | |
base_uri = "https://2014.spaceappschallenge.org/" | |
category_links = Nokogiri::HTML(open("#{base_uri}/challenge")).css('#category_array a').map {|l| l.attributes['href'].text} | |
categories = category_links.map {|cat| cat.split('/').last} | |
category_hashes = {} | |
category_links.each_with_index do |link, index| | |
category = categories[index] | |
challenge_links = Nokogiri::HTML(open("#{base_uri}#{link}")).css('#challenge_array a').map {|l| l.attributes['href'].text} | |
category_hashes.merge!({category => {links: challenge_links} }) | |
category_challenges = [] | |
challenge_links.each do |challenge_link| | |
challange_html = Nokogiri::HTML(open("#{base_uri}#{challenge_link}")) | |
challenge_name = challange_html.at_css('h2').text | |
challenge_text = challange_html.at_css('#descriptionTab').inner_html | |
category_challenges << {challenge_name => challenge_text} | |
end | |
category_hashes[category][:challenges]=category_challenges | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment