Created
September 27, 2010 17:19
-
-
Save eric/599412 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'johnson' | |
require 'open-uri' | |
require 'yajl' | |
# Grab the source to the Javascript JSON implementation | |
json_js = open('http://www.json.org/json2.js').read | |
# Strip that silly alert at the top of the file | |
json_js.gsub!(/^(alert.*)$/, '/* \1 */') | |
# This is some Javascript you wanted to get something from | |
some_js = open('http://www.mol.fi/platser/scripts/scripts2.jsp?lang=sv').read | |
result = Johnson.evaluate(<<-EOF) | |
/* Include the JSON source code */ | |
#{json_js} | |
/* Include the source code you wanted to get something from */ | |
#{some_js} | |
/* Turn the things you wanted out into a string */ | |
JSON.stringify([ LBval_3, LBtxt_3 ]) | |
EOF | |
# Get the result back in ruby | |
ruby_result = Yajl::Parser.parse(result) | |
# Do something with it | |
puts ruby_result.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment