Fetch Content From HTML in Ruby
The best way to fetch data from html based on css or html tags is to use NOKOGIRI gem.
Here is the process to achieve it:
$ sudo gem install nokogiri
# Open your controller
#Include open-uri & nokogiri
require ‘open-uri’
require ‘nokogiri’
class FetchController < ApplicationController
def index
doc = Nokogiri::HTML(open(‘kunalinfotech.net/company/about-us.html’))
doc.css(‘body,h1′).each do |link| @fetch = link.content
end
# Index.html.erb
<%= @fetch %>
Thanks. Saved my day.