Opening a WIKI URL with a comma using `open-uri`

I start with an error OpenURI::HTTPError: 403 Forbidden when I try a opensemicolon URL (or other special characters, for example .). I can open the same URL in the browser.

require 'open-uri'
url = "http://en.wikipedia.org/wiki/Thor_Industries,_Inc."
f = open(url)
# throws OpenURI::HTTPError: 403 Forbidden error

How to avoid such a URL?

I tried to hide the URL from CGI::escapeand I get the same error.

f = open(CGI::escape(url))
+5
source share
1 answer

Typically, you just need a module cgi, then use CGI::escape(str).

require 'cgi'
require 'open-uri'
escaped_page = CGI::escape("Thor_Industries,_Inc.")
url = "http://en.wikipedia.org/wiki/#{escaped_page}"
f = open(url)

However, this does not seem to work for your specific instance and still returns 403. I will leave this here for reference, regardless.


: , , . , , , "" (, , ), . ( Net::HTTP), :

User-Agent IP .

:

open("http://en.wikipedia.org/wiki/Thor_Industries,_Inc.",
  "User-Agent" => "Ruby/#{RUBY_VERSION}")
+7

All Articles