News Fetcher is a simple gem that uses Nokogiri for parsing HTML documents fetched from the Internet and returns selected data that can be printed out to Unix STDOUT in a variety of colors like so:
or
$ gem install news_fetcher
or directly in your Gemfile
gem 'news_fetcher'
News Fetcher uses the OpenURI Ruby module to get the HTML content of a webpage and Nokogiri to parse the response given a structure (e.g. XPath).
Use the fetch
method to get the information you want from a certain url, also specifying the xPath you are looking for and the color you want to see your results (terminal only):
document, nodes = NewsFetcher.fetch('https://techcrunch.com', 'h2/a', 'orange')
document ### The Nokogiri HTML Document object
nodes ### The matching nodes found in the document
Available colors are:
- Black
- Red
- Green
- Orange
- Blue
- Purple
- Cyan
- Gray
If you don't specify the color it will take black by default
News Fetcher also provides a CLI so you can call it from your favorite terminal and see the results:
nf fetch http://www.bbc.com/ div/h3/a blue
or
news_fetcher fetch http://edition.cnn.com/tech div/h3/a/span red
- Copyright (c) 2016 Kevin Martin. See LICENSE.txt for details.