Class: GoldSilverNepal::Scraper
- Inherits:
-
Object
- Object
- GoldSilverNepal::Scraper
- Defined in:
- lib/gold_silver_nepal.rb
Overview
scrapper for gold silver rate
Constant Summary collapse
- GOLD_SILVER_URL =
"https://www.fenegosida.org/"
Class Method Summary collapse
Class Method Details
.scrape ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gold_silver_nepal.rb', line 12 def self.scrape html = URI.open(GOLD_SILVER_URL) @doc = Nokogiri::HTML(html) fine_gold_gram = @doc.css('div.rate-gold p:contains("FINE GOLD (9999)") b')[0]&.text&.strip&.to_i fine_gold_tola = @doc.css('div.rate-gold p:contains("FINE GOLD (9999)") b')[1]&.text&.strip&.to_i tejabi_gold_gram = @doc.css('div.rate-gold p:contains("TEJABI GOLD") b')[0]&.text&.strip&.to_i tejabi_gold_tola = @doc.css('div.rate-gold p:contains("TEJABI GOLD") b')[1]&.text&.strip&.to_i silver_gram = @doc.css('div.rate-silver p:contains("SILVER") b')[0]&.text&.strip&.to_i silver_tola = @doc.css('div.rate-silver p:contains("SILVER") b')[1]&.text&.strip&.to_i @params = { "fine_gold_gram" => fine_gold_gram, "fine_gold_tola" => fine_gold_tola, "tejabi_gold_gram" => tejabi_gold_gram, "tejabi_gold_tola" => tejabi_gold_tola, "silver_gram" => silver_gram, "silver_tola" => silver_tola } @params rescue StandardError => error puts "An error occurred: #{error.message}" end |