Showing posts with the label data scraping

Data Scrapping in rails

go to your terminal create a directory mkdir ruby_data_scrapping create directory mkdir lib cd lib/ touch scraper.rb gem install nokogiri  // install gems in local gem install httparty gem install byebug Write code in your scraper.rb require "httparty" require "nokogiri" require "byebug" class Scraper   attr_accessor :parse_page   def initialize       doc = HTTParty.get("")       @parse_page ||= Nokogiri::HTML(doc)   end   def get_prices      item_container.first(2){|x| x.text}   end   private     def item_container        parse_page.css(".tv-data-table__tbody").first.css(".tv-screener-table__result-row").css(".tv-screener-table__cell")     end   prices =   (0...prices.size).each do |index|       puts "Price: #{prices[index]}"   end end now run this scraper ruby scraper.rb