Cannot read a page with open-uri

open-uri have been working fine, until I used it to open, when it returned a
empty string.
I don’t know what is the problem. Is there any page that can not be open
with open-uri? or I need some special argument to read it?

I don’t have time to take a close look right now, but when I had this
problem playing with web robots, it was first because some sites
required a user-agent string from a common web browser.

The internet says you can use open-uri as follows:

open(uri, “User-Agent” => ‘Mozilla/4.0 (compatible; MSIE 6.0; Windows NT

Or other user agent–the above is for Internet Explorer.

Good luck,

Dan Z. wrote:

open(uri, “User-Agent” => ‘Mozilla/4.0 (compatible; MSIE 6.0; Windows NT

It works. Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs