Posts

Showing posts with the label data scrap

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("https://in.tradingview.com/markets/currencies/rates-africa/")       @parse_page ||= Nokogiri::HTML(doc)   end   def get_prices      item_container.first(2).last.children.map{|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 = Scraper.new.get_prices   (0...prices.size).each do |index|       puts "Price: #{prices[index]}"   end end now run this scraper ruby scraper.rb