Reputation: 22810
OK, so my situation is rather simple :
Code :
require 'open-uri'
url = "http://en.wikipedia.org/w/api.php?action=query&format=xml&titles=Italy|France&prop=revisions&rvprop=content";
xml = open(url).read
When titles
is set to, e.g. Italy
, it works fine, but setting it to Italy|France
seems to be causing issues. (supposedly its problem is the |
character?)
Here's the error :
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/uri/common.rb:176:in `split': bad URI(is not URI?): http://en.wikipedia.org/w/api.php?action=query&format=xml&titles=France|Italy&prop=revisions&rvprop=content (URI::InvalidURIError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/uri/common.rb:211:in `parse'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/uri/common.rb:747:in `parse'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:33:in `open'
from test.rb:41:in `<main>'
Any ideas?
Upvotes: 0
Views: 99
Reputation: 888
you can use
encodeURIComponent()
Refer:Unescape special characters correctly from the URL in Rails 3.0.3
Also try:
CGI.escape(url);
Upvotes: 1