BACKGROUND: The script below logs into my salesforce.com account and tries to click a bunch of "download" links and save the resulting .zip export files locally.
I'm using jruby and celerity (which is a jruby wrapper around htmlunit, a headless browser, which also supports javascript).
The requirement is that it runs from a LINUX command line without a gui/browser installed. The headless browser also needs to support javascript otherwise salesforce.com returns an error and it will not render the download links. (I tried CURL but it fails since it does not support javascript).
(Currently the script works fine when run from the command line on a WINDOWS box)
QUESTION:
When i try to run this from a linux box, i receive the error below and the script does not appear to login to salesforce. i believe the .js warning is ok (i think), but i don't understand what the VBScript not supported in Window.execScript() warning means?:
[root@ip-10-114-241-55 ~]# jruby download_sf_export_files.rb
Jan 18, 2011 2:16:41 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'https://www.salesforce.com/common/assets/js/global2.js?date=100817', but got 'application/x-javascript'.
Jan 18, 2011 2:16:41 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'https://www.salesforce.com/common/assets/thirdparty/omniture/s_code3.js?date=101012', but got 'application/x-javascript'.
Jan 18, 2011 2:38:05 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'https://na7.salesforce.com/static/101210/js/functions.js', but got 'application/x-javascript'.
Jan 18, 2011 2:38:06 AM com.gargoylesoftware.htmlunit.javascript.host.Window jsxFunction_execScript
WARNING: VBScript not supported in Window.execScript().
-----install instructions------
download jruby: http://jruby.org/download
install gem from command line: jruby -S gem install celerity
run script from command line: jruby download_sf_export_files.rb
-----download_sf_export_files.rb-------
require "rubygems"
require "celerity"
browser = Celerity::Browser.new
browser.goto('https://na7.salesforce.com')
browser.text_field(:name, 'username').value = 'myuserlogin@domain.com'
browser.text_field(:name, 'pw').value = 'mysecretpassword'
browser.button(:name, 'Login').click
browser.goto('https://na7.salesforce.com/ui/setup/export/DataExportPage/d')
## assume multiple 'download' links if a large SF data export
## group all links in a map, iterate and click each one
i=1
hrefs = browser.links.map { |link| link.href if link.text =~ /download/ }.compact hrefs.each do |href|
browser.link(:url, href).download
puts "found a 'download' link on page, clicking link..."
io = browser.link(:text, "download").download
File.open("sf_zip_file_#{i}.zip", "w+") { |file| file.write(io.read) }
i+=i
end