desc "Import incoming calls" task :fetch_incomingcalls => :environment do # Logs into manage.phoneprovider.co.uk and retrieved list of incoming calls. require 'rubygems' require 'mechanize' require 'logger' # Create a new mechanize object agent = Mechanize.new { |a| a.log = Logger.new(STDERR) } # Load the phoneprovider website page = agent.get("https://manage.phoneprovider.co.uk/login") # Select the first form form = agent.page.forms.first form.username = 'username' form.password = 'password' # Submit the form page = form.submit form.buttons.first # Click on link called Call Logs page = agent.page.link_with(:text => "Call Logs").click # Click on link called Incoming Calls page = agent.page.link_with(:text => "Incoming Calls").click # Prints out table rows # puts ('table > tr') # Print out the body as a test # puts page.body # StackOverflow Snippet Nokogiri::HTML(html).xpath("//table/tbody/tr[not(@class)]").collect do |row| timestamp = row.at("td[1]").text.strip source = row.at("td[2]").text.strip destination = row.at("td[3]").text.strip duration = row.at("td[4]").text.strip {:timestamp => timestamp, :source => source, :destination => destination, :duration => duration} end