I have used hpricot before for grabing content from websites that are within some HTML tags however I am trying to build an array of all the flashvars found on this page http://view-source:http://megavideo.com/?v=014U2YO9
require 'hpricot'
require 'open-uri'
flashvars = Array.new
doc = Hpricot(open("http://megavideo.com/?v=014U2YO9"))
for flashvars in (doc/"/param[@name='flashvars']") do
flashvars << flashvar
end
I have been trying with the above code snippet, hopefully I was on the right tracks, would anyone be able to help me further?
Thankyou
You have used syntax indicating that you are trying to fetch attributes from
<param>elements, but no such markup exists on that page. There are a plethora of JavaScript assignments to properties of aflashvarobject. Assuming that these are what you want, you don’t need Hpricot, just a regex for the JS. This seems to work:Note that this leaves all values as strings in Ruby, even values that were numbers in JavaScript. As it strips off leading/trailing quote marks for the JavaScript strings, the result is that you cannot discern
flashvars.foo = 42;fromflashvars.bar = "42";.