Skip to content

Instantly share code, notes, and snippets.

@karpelcevs
Created March 30, 2012 13:47
Show Gist options
  • Save karpelcevs/2251671 to your computer and use it in GitHub Desktop.
Save karpelcevs/2251671 to your computer and use it in GitHub Desktop.
Superakcijas
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
@url = "http://www.superakcijas.lv/public/"
@deals = "more_deals.php"
@response = ''
@search_string = 'iPhone'
begin
while true
begin
open(@url + @deals) { |f|
puts "Fetched document: #{f.base_uri}"
puts "\t Content Type: #{f.content_type}\n"
puts "\t Charset: #{f.charset}\n"
# Save the response body
@response = f.read
}
# HPricot RDoc: http://code.whytheluckystiff.net/hpricot/
doc = Hpricot(@response)
(doc/"p.alt_parr/a").each do |link|
if link.inner_html.include? @search_string
puts "This is it!"
buy_link = link.attributes['href'].gsub("index.php?deal", "buy.php?id");
puts @url + buy_link
`open #{@url + buy_link}`
exit
end
end
rescue Exception => e
print e, "\n"
end
puts "Not found this time..."
sleep 3
puts "Continuing"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment