here is the URL (spans 2 lines) and it fails with a bad uri message
http://quote.yahoo.com/d/quotes.csv?s=MS+^DJI+^GSPC+^IXIC+IWB+IWM+IWV+TMW+^VIX+^TV.N+&f=d1t1sl1c1&e=csv
The message I get is URI::InvalidURIError: bad URI(is not URI?):
The same URI in a web page returns quote.csv, as expected
Any ideas? I am stumped
thanks in advance!
Joe
···
--
Posted via http://www.ruby-forum.com/ .
Whenever I do web stuff I prefer using an external library. ie Mechanize
Here is what it'd look like with mechanize :
require 'Mechanize'
agent = Mechanize.new
file = agent.get('uri') #Returns a Mechanize::File object
file.save('filename')
You could also use blocks if you wanted.
That will save the file in the same directory as the script.
···
--
Posted via http://www.ruby-forum.com/ .
I tried escaping the ^ and other symbols also but no luck
Joe
···
--
Posted via http://www.ruby-forum.com/ .
11142
(-- --)
7 October 2011 19:34
6
You need to escape the carets (^) for Ruby to understand - URI library
is pretty strict about what it accepts. You will probably need to
escape all other funky chars, too.
-- Matma Rex
11142
(-- --)
7 October 2011 20:58
7
"Escape" as in "URL-escape". For example, ^ becomes %5E. You can use
the CGI.escape() method for this (you'll need to require 'cgi' first).
-- Matma Rex
···
2011/10/7 Joe Collins <joec_49@hotmail.com>:
I tried escaping the ^ and other symbols also but no luck
11142
(-- --)
8 October 2011 12:46
8
Not backslash-escape, URL-escape - with the percent signs. Read my
previous post again - you can use CGI.escape() for this. Also read
this: Percent-encoding - Wikipedia
-- Matma Rex
···
2011/10/7 Joe Collins <joec_49@hotmail.com>:
open("http://quote.yahoo.com/d/quotes.csv\?s=MS+\^DJI+\^GSPC+\^IXIC+IWB+IWM+IWV+TMW+\^VIX+\^TV.N+\&f=d1t1sl1c1\&e=csv"\ )
Here it is escaped and it still fails....any ideas?