Skip to content

Instantly share code, notes, and snippets.

@oliverbarnes
Created August 26, 2010 03:39
Show Gist options
  • Save oliverbarnes/550745 to your computer and use it in GitHub Desktop.
Save oliverbarnes/550745 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mechanize'
agent = Mechanize::new
agent.user_agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_0; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Safari/533.4"
begin
page = agent.get 'http://asdapriceguarantee.co.uk/Compare-Prices/ASDA-receipt.aspx'
rescue Mechanize::ResponseCodeError
puts "ResponseCodeError - Code: #{$!}"
end
receipt_form = page.form_with(:name => 'aspnetForm')
receipt_form.set_fields(
'ctl00$PageContent$StoreNumber' => '4939',
'ctl00$PageContent$OperatorNumber' => '00001858',
'ctl00$PageContent$TillNumber' => '04',
'ctl00$PageContent$TransactionNumber' => '07374',
'ctl00$PageContent$ReceiptDateDay' => ' 16',
'ctl00$PageContent$ReceiptDateMonth' => '08',
'ctl00$PageContent$ReceiptDateYear' => '10',
'ctl00$PageContent$ReceiptTimeMinutes' => '57',
'ctl00$PageContent$ReceiptTimeSeconds' => '21',
'ctl00$PageContent$ReceiptTimeHours' => '10'
)
return_page = agent.submit receipt_form
puts "--------------------------------"
puts ""
%w{SecondCell ThirdCell FourthCell FifthCell}.each_with_index do |cell, i|
return_page.body.match /<td class="#{cell}">([^<]+)<\/td>/
competitor = $1
return_page.body.match /<span id="ctl00_SubTitleContent_PriceDiff#{i+1}">([^<]+)<\/span>/
puts "#{competitor}: #{$1}"
end
return_page.body.match /<span id="ctl00_PageContent_TotalSavingsCount">([^<]+)<\/span>/
puts ""
puts "ASDA can save you up to: #{$1}!"
puts ""
puts "--------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment