Class: Wco::ScrapeWsj
- Inherits:
-
Object
- Object
- Wco::ScrapeWsj
- Defined in:
- lib/wco/scrape_wsj.rb
Instance Method Summary collapse
-
#initialize(site: nil, max_count: 2) ⇒ ScrapeWsj
constructor
A new instance of ScrapeWsj.
Constructor Details
#initialize(site: nil, max_count: 2) ⇒ ScrapeWsj
Returns a new instance of ScrapeWsj.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wco/scrape_wsj.rb', line 6 def initialize site: nil, max_count: 2 site ||= Wco::Site.find_by slug: 'wsj' # out = HTTParty.get( site.origin ).response.body # out = `curl #{site.origin}` 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. end end end end |