Sha256: be83fe3c448434348286a2f17d4fd053b227611c798d54d729bfa60f1cc419a3

Contents?: true

Size: 981 Bytes

Versions: 5

Compression:

Stored size: 981 Bytes

Contents

# -*- ruby -*-
require 'mechanize'
# require 'pry'

module Scrapers
  module Wunderground

    def self.scrape(url)
      results = Hash.new

      Mechanize.start do |m|
        m.get(url)
        results["title"] = m.page.title
        results["url"] = m.page.uri.to_s
        snippet = m.page.search('#weather-snippet')
        results["snippet"] = snippet.to_html.gsub(/[\n\t]+/,'')
        results["location"] = snippet.at_css('h1').text.strip
        results["image"] = snippet.at_css('#condition-img div img')['src']
        results["temp"] = snippet.at_css('#temp').text.gsub(/[[:space:]]+/,' ').strip
        results["condition"] = snippet.at_css('#condition').text.strip
        results["feel"] = snippet.at_css('#feel').text.gsub(/[[:space:]]+/,' ').strip
        results["high"] = snippet.at_css('.high').text.gsub(/[[:space:]]+/,' ').strip
        results["low"] = snippet.at_css('.low').text.gsub(/[[:space:]]+/,' ').strip
      end

      results
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
scrapers-3.2.0 lib/scrapers/wunderground.rb
scrapers-3.1.0 lib/scrapers/wunderground.rb
scrapers-3.0.0 lib/scrapers/wunderground.rb
scrapers-2.1.0 lib/scrapers/wunderground.rb
scrapers-2.0.2 lib/scrapers/wunderground.rb