Sha256: 30c6916c5932377e0adecff56fda264299ce219dc11fd56d4446500359452306

Contents?: true

Size: 599 Bytes

Versions: 116

Compression:

Stored size: 599 Bytes

Contents

require 'httparty'

class Wco::ScrapeWsj

  def initialize site: nil, max_count: 2
    site ||= Wco::Site.find_by slug: 'wsj'

    out = HTTParty.get( site.origin ).response.body
    out = Nokogiri::HTML(out)
    out.css('h3').each_with_index do |headline, idx|
      if idx < max_count
        puts! headline.text, 'headline'
        h = Wco::Headline.create({
          date: Time.now.to_date,
          site: site,
          name: headline.text,
        })
        if h.persisted?
          print '.'
        else
          puts! h.errors.full_messages
        end
      end
    end
  end

end

Version data entries

116 entries across 116 versions & 1 rubygems

Version Path
wco_models-3.1.0.74 lib/wco/scrape_wsj.rb
wco_models-3.1.0.73 lib/wco/scrape_wsj.rb
wco_models-3.1.0.72 lib/wco/scrape_wsj.rb
wco_models-3.1.0.71 lib/wco/scrape_wsj.rb
wco_models-3.1.0.70 lib/wco/scrape_wsj.rb
wco_models-3.1.0.69 lib/wco/scrape_wsj.rb
wco_models-3.1.0.67 lib/wco/scrape_wsj.rb
wco_models-3.1.0.66 lib/wco/scrape_wsj.rb
wco_models-3.1.0.65 lib/wco/scrape_wsj.rb
wco_models-3.1.0.64 lib/wco/scrape_wsj.rb
wco_models-3.1.0.63 lib/wco/scrape_wsj.rb
wco_models-3.1.0.62 lib/wco/scrape_wsj.rb
wco_models-3.1.0.61 lib/wco/scrape_wsj.rb
wco_models-3.1.0.60 lib/wco/scrape_wsj.rb
wco_models-3.1.0.59 lib/wco/scrape_wsj.rb
wco_models-3.1.0.58 lib/wco/scrape_wsj.rb
wco_models-3.1.0.57 lib/wco/scrape_wsj.rb
wco_models-3.1.0.56 lib/wco/scrape_wsj.rb
wco_models-3.1.0.55 lib/wco/scrape_wsj.rb
wco_models-3.1.0.54 lib/wco/scrape_wsj.rb