Skip to content

Instantly share code, notes, and snippets.

@mcmajkel-gist
Created August 10, 2012 16:55
Show Gist options
  • Save mcmajkel-gist/3315601 to your computer and use it in GitHub Desktop.
Save mcmajkel-gist/3315601 to your computer and use it in GitHub Desktop.
stacje_wawa_pb95
require 'rubygems'
require 'nokogiri'
require 'open-uri'
url = "http://www.cenapaliw.pl/index.php?o=&m=95&l=7&k=327"
doc = Nokogiri::HTML(open(url))
ceny = []
doc.css("#priser tr").each do |item|
nazwa = item.at_css(':first-child').text
price = item.text[/\d+,\d\d/]
lokalizacja = item.at_css(':nth-child(2)').text if price
stacja = {nazwa: nazwa, lokalizacja: lokalizacja, cena: price.gsub(',','.').to_f} if lokalizacja
ceny << stacja unless stacja.nil?
#
end
ceny.sort_by! {|c| c[:cena]}
ceny.each {|c| puts "#{c[:nazwa]} - #{c[:lokalizacja]} - #{c[:cena]} zl" }
@mcmajkel-gist
Copy link
Author

pobieranie posortowanych cen paliw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment