Class: Scraper
- Inherits:
-
Object
- Object
- Scraper
- Defined in:
- lib/scraper.rb
Instance Method Summary collapse
Instance Method Details
#get_articles(stage) ⇒ Object
2 3 4 5 6 7 8 9 |
# 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) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# 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 |