require 'rubygems' require 'open-uri' require 'hpricot' require 'rss/maker' @url = "http://www.millionreasonswhylatviaisthebestcountryintheworld.com/lv/all/newest/" @response = '' begin open(@url, "User-Agent" => "Ruby/#{RUBY_VERSION}", "From" => "atoms@tups.lv", "Referer" => "http://tups.lv/blog/") { |f| @response = f.read } doc = Hpricot(@response) docs = [] doks = [] links = [] docs = (doc/"div.ent") 10.times do | num | (docs[num]/"div.val").remove (docs[num]/"div.info").remove (docs[num]/"div[1]").remove (docs[num]/"br").remove link = (docs[num]/"a").last.to_s linkid = link.gsub(/<\/?[^>]*>/, "") linkid = linkid.split('#') linktopage = 'http://www.millionreasonswhylatviaisthebestcountryintheworld.com/lv/' + linkid[1] links << linktopage doks << docs[num] end version = "2.0" # ["0.9", "1.0", "2.0"] destination = "/home/-httpd/tups.lv/million/index.xml" # local file to write content = RSS::Maker.make(version) do |m| m.channel.title = "Million Reasons Why Latvia Is The Best Country In The World" m.channel.link = "http://www.millionreasonswhylatviaisthebestcountryintheworld.com" m.channel.description = "Million Reasons Why Latvia Is The Best Country In The World" 10.times do | nn | i = m.items.new_item i.title = "Million Reasons Why Latvia Is The Best Country In The World" i.link = links[nn] i.description = doks[nn] end end File.open(destination,"w") do |f| f.write(content) end rescue Exception => e print e, "\n" end