I have the following ruby script:
require "rubygems"
require "rest-client" #although not required in the program
require "open-uri"
require "nokogiri"
puts "Opening file"
page=File.open("file.html","r"){|file| file.read}
puts page
page = Nokogiri::HTML(page)
puts page.class
#Filters content of page to select all references to the documents filing date
td_rows = page.css('td i.blue')
puts td_rows
I can run this script from CodeRunner or TextWrangler and invoke it from the terminal using ruby 'filename'. However, I am trying to get the script to run at a certain point in time and have tried calling the script using Keyboard Maestro or Platypus but although it runs it does not seem to complete the line
td_rows = page.css('td i.blue')
The variable td_rows contains nothing. Does anyone have any idea why this will not work?
Many thanks
I managed to find out why the nokogiri parse was not working.
For some reason, if the page was opened from the web, the script would work but if the web page was saved to disk first and then opened it did not. I found that when the page was opened from disk it encountered a nokogiri error and only read and parsed the first few lines of the file. The error was due to a html comment not being closed on the same line but on a subsequent line.
I managed to overcome this problem by reading the file with the mode "rb" instead of just "r". i.e. if I replace the file.open line with:
nokogiri correctly parses the file.