Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #requires
- require 'rubygems'
- require 'mechanize'
- #require 'logger'
- #set the agent and setup the logging
- agent = Mechanize.new
- #agent.log = Logger.new "mech.log"
- #specify the site, in this case expo motorcars
- page = agent.get('http://something.com/invlist.php')
- #write out to a file, debugging
- #File.open('output.txt', "w") do |f|
- # f.puts page.links_with(:text => 'Details')
- #end
- #parse each link from the inventory page
- links = page.links_with(:text => 'Details')
- links.each do|link|
- page = link.click
- # puts page.parser.xpath('//table').to_html
- year = page.body.match /YEAR - <\/font>(.+)<\/a>/
- puts "Year : #{year[1]}"
- make = page.body.match /MAKE - <\/font>(.+)<\/a>/
- puts "Make : #{make[1]}"
- model = page.body.match /MODEL - <\/font>(.+)<\/a>/
- puts "Model : #{model[1]}"
- mileage = page.body.match /MILEAGE - <\/font>(\d+)<\/a>/
- puts "Mileage : #{mileage[1]}"
- vehidennum = page.body.match /V.I.N# - <\/font>(\w+)<\/a>/
- puts "VIN# : #{vehidennum[1]}"
- price = page.body.match(/\$(.+)<\/a>/)
- # price = price.float
- puts "Price : #{price[1]}"
- end
- ====================================================================================
- vraa@ruby-ubuntu:~/car_mechanize$ ruby simple.rb
- Year : 2011
- Make : Aston Martin
- Model : Rapide Sedan
- Mileage : 1374
- VIN# : SCFHDDAJXBAF01727
- Price : 30k
- Year : 2011
- Make : BMW
- Model : 535i SPORT
- Mileage : 11959
- VIN# : WBAFR7C56BC604263
- Price : 30k
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement