Class: Tmxnews::Scraper
- Inherits:
-
Object
- Object
- Tmxnews::Scraper
- Defined in:
- lib/tmxnews/scraper.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
2 3 4 |
# File 'lib/tmxnews/scraper.rb', line 2 def text @text end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/tmxnews/scraper.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/tmxnews/scraper.rb', line 2 def url @url end |
Class Method Details
.scrape_nyt ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/tmxnews/scraper.rb', line 4 def self.scrape_nyt doc = Nokogiri::HTML(open("https://www.nytimes.com")) article = self.new article.title = doc.search("h2.story-heading").first.text article.text = doc.search("article").css("ul li").text article.url = doc.search("h2.story-heading").first.css("a").attr("href").value article end |
.scrape_wsj ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/tmxnews/scraper.rb', line 13 def self.scrape_wsj doc = Nokogiri::HTML(open("https://www.wsj.com")) article = self.new article.title = doc.search("h3.wsj-headline").first.text article.text = doc.search("p.wsj-summary").first.text article.url = doc.search("h3.wsj-headline").first.css("a").attr("href").value article end |