class Scraper
Public Instance Methods
get_articles(stage)
click to toggle source
# File lib/scraper.rb, line 2 def get_articles(stage) html = Nokogiri::HTML(open("https://www.thebump.com")) all_sections = html.css(".homepage-panel---articles") all_sections[stage].css(".homepage-panel--item").collect do |article| article_url = article.attribute("href").value scrape_article(article_url) end end
scrape_article(article_url)
click to toggle source
# File lib/scraper.rb, line 11 def scrape_article(article_url) html = Nokogiri::HTML(open(article_url)) article_hash = { title: html.css("div#pre-content-container h1").text.strip, subtitle: html.css("div#pre-content-container .dek").text.strip, author: html.css("div#pre-content-container .contributor-name").text.strip, content: html.css("div.body-content p, div.body-content h2, div.body-content ul") } Article.new_from_hash(article_hash) end