Skip to content

@dannymcc /gist:2312571
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
desc "Import Service Provider Location"
task :fetch_serviceproviderlocation => :environment do
# Logs into service provider and retrieved latitude and longitude.
require 'rubygems'
require 'mechanize'
require 'logger'
require 'nokogiri'
# Create a new mechanize object
agent = Mechanize.new
# Load the Peoplesafe website
page = agent.get("http://serviceprovider.co.uk")
# Select the first form
form = agent.page.forms.first
form.username = 'USERNAME'
form.password = 'PASSWORD'
# Submit the form
page = form.submit form.buttons.first
script = page.at('/html/head/script[not(@src)]')
# Find the first <script> in the head that does not have src="..."
#script = html.at_xpath('/html/head/script[not(@src)]')
# Use a regex to find the correct code parts in the JS, using named captures
parts = script.text.match(/new GLatLng\(\s*(?<lat>.+?)\s*,\s*(?<long>.+?)\s*\)/)
p parts[:lat], parts[:long]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.